Reputation: 21
AlertDialog.Builder fpdialog = new AlertDialog.Builder(context);
ListView fpathlist = new ListView(context);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,android.R.layout.simple_expandable_list_item_1, fpathdata());
OnItemClickListener listener = new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
final int position, long arg3) {
// TODO Auto-generated method stub
for (int i=0;i<=position;i++)
{
if (i==position)
{
CharSequence[] pathString = {"在地图显示","发短信","共享","删除"};
final AlertDialog.Builder pathlist = new AlertDialog.Builder(context);
pathlist.setTitle("路线收藏");
pathlist.setItems(pathString, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//Here I want to dismiss the fpdialog
}});
pathlist.show();
}
}
}
};
fpathlist.setOnItemClickListener(listener);
fpathlist.setAdapter(adapter);
fpdialog.setView(fpathlist);
fpdialog.show();
Upvotes: 0
Views: 2875
Reputation: 1789
If you simply want to dismiss the dialog when the button is pressed, call dialog.dismiss() inside the onClick() method.
Upvotes: 1
Reputation: 128448
When you're ready to close your dialog, you can dismiss it by calling dismiss()
on the Dialog object. If necessary, you can also call dismissDialog(int)
from the Activity, which effectively calls dismiss() on the Dialog for you.
If you are using onCreateDialog(int) to manage the state of your dialogs , then every time your dialog is dismissed, the state of the Dialog object is retained by the Activity. If you decide that you will no longer need this object or it's important that the state is cleared, then you should call removeDialog(int)
. This will remove any internal references to the object and if the dialog is showing, it will dismiss it.
To dismiss a ProgressDialog use ProgressDialogName.dismiss().
For e.g. Mydialog.dismiss()
Refer to the Android-SDK for more information.
Have a look at this example .
Upvotes: 2