When an item in my ListView is clicked, I have several options pop up in a dialog for the user to choose. However, there are varying scenarios where I'd like to disable one or more options so the user cannot choose them. Here's some code.
public class MyApp extends ListActivity implements OnItemClickListener, OnItemLongClickListener {
private static final int HOW_MANY = 4;
private static final int ADD = 0;
private static final int EDIT = 1;
private static final int OPEN = 2;
private static final int DELETE = 3;
private String[] myItemClickDialog = null;
...
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.mylayout);
this.myItemClickDialog = new String[HOW_MANY];
this.myItemClickDialog[ADD] = "Add";
this.myItemClickDialog[EDIT] = "Edit";
this.myItemClickDialog[OPEN] = "Open";
this.myItemClickDialog[DELETE] = "Delete";
}
@Override
public final boolean onItemLongClick(final AdapterView<?> parent,
final View view, final int position, final long id) {
final Context context = this;
Builder builder = new Builder(context);
builder.setTitle("Options");
String[] items = this.myItemClickDialog;
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
switch (which) {
case ADD:
//Do stuff
break;
case EDIT:
//Do stuff
break;
case OPEN:
//Do stuff
break;
case DELETE:
//Do stuff
break;
}
}
// Rest of code here
I would like to be able to disable (by dimming) a particular option, such as the DELETE option or the OPEN option depending on which list item was clicked (I got that part covered, that is, the detection piece).