Reputation: 6912
I use below code to show folder list in 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
}
});
I want to make the AlertDialog's NegativeButton always show, and the AlertDialog's PositiveButton only show while the list item number is 0. How to arrive it?
Upvotes: 0
Views: 534
Reputation: 4670
try this, it work fine..
Call Dialog Method Like this,,,,
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();
}
Upvotes: 3
Reputation: 10969
Put condition, if your list item gives 0 then then allow to show positive button else not.
I tried using flag when its not true its wont show positive button else it will show both.
Below is the code
AlertDialog.Builder ListDialog;
AlertDialog contactMessage;
flag=true;
ListDialog = new AlertDialog.Builder(AdvancedListViewActivity.this);
ListDialog.setTitle("Folder List");
if(flag!=true){
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
}
});
contactMessage = ListDialog.create();
contactMessage.show();
Same thing you can also do, check condition while your list item is not zero avoid positive button else show it.
Upvotes: 1