MainActivity.java :
public class MainActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FragmentManager fm = getSupportFragmentManager(); dialogfragment testDialog = new dialogfragment(); testDialog.setRetainInstance(true); testDialog.show(fm, "fragment_name"); }}Dialogfragment.java :
public class Dialogfragment extends DialogFragment { public void TestDialog() { // Empty constructor required for DialogFragment } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { View view = inflater.inflate(R.layout.dialog, container); return view; } }dialog.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/edit_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="vertical"> <TextView android:id="@+id/lbl_your_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello from Mark's Playground, DialogFragment Demo"/> </LinearLayout>
Comments
Post a Comment