I'm working on a Campus Map App. The Map Activity is on the Main Activity, however, I have a different activity for the Custom Dialog. I always get this custom dialog.
When in fact I want it to appear like this.
I have this code for this Activity
public class AdminActivity extends FragmentActivity{
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(AdminActivity.this);
builder.setTitle(R.string.layers)
.setItems(R.array.layer_options, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
// The 'which' argument contains the index position
// of the selected item
}
});
return builder.create();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
Dialog dialog=onCreateDialog(savedInstanceState);
dialog.show();
}
}
And this code is a part from the main activity where I'm going to call the dialog..
@Override
public boolean onOptionsItemSelected(MenuItem item){
AdminDialog adminDialog;
switch(item.getItemId()){
case R.id.about:
Intent aboutUs = new Intent("com.android.cmumap.ABOUT");
startActivity(aboutUs);
break;
case R.id.search:
break;
case R.id.layers:
adminDialog= new AdminDialog();
adminDialog.show(getFragmentManager(), "custom-tag-goes-here");
break;
}
return false;
}
How do I achieve calling the map activity for my AdminActivity? Thank You.
Your class should subclass DialogFragment
, not FragmentActivity
. Be sure to @Override
the onCreateDialog(...)
method. You can also get rid of your onCreate(...)
method as that is not needed with a DialogFragment
.
To display the DialogFragment
, instead of using an Intent
like you would for an Activity
, do the following from your map activity. Note that I renamed your class because now it is not an Activity
but rather a Dialog
:
adminDialog= new AdminDialog();
adnimDialog.show(getFragmentManager(), "custom-tag-goes-here");