我使用下面的代碼在AlertDialog中顯示文件夾列表:
ListDialog = new AlertDialog.Builder(MyActivity.this);
ListDialog.setTitle("Folder List");
ListView folder = new ListView(MyActivity.this);
//scan folder
folder.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
//scan sub-folder
});
ListDialog.setPositiveButton("Save", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
//do something
}
});
ListDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
//back
}
});
我想讓 AlertDialog的 NegativeButton 總是顯示,而當 list item 數是0時, AlertDialog的 PositiveButton
才顯示。如何實現?
調用 Dialog 方法:
dialog_message("Dialog msg");
public void dialog_message(String msg)
{
final AlertDialog alertDialog = new AlertDialog.Builder(BottomMenu_Event.this).create();
alertDialog.setTitle("Title");
alertDialog.setIcon(R.drawable.icon);
alertDialog.setMessage(msg);
alertDialog.setButton("Save", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
//Your Code....
}
});
alertDialog.setButton2("Cancel", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
alertDialog.dismiss();
}
});
alertDialog.show();
}