I have a ListView which is display several String and a method of setOnItemLongClick which will call and pop out a dialog options menu which has the options of Add, View and Delete. The setOnItemLongCLick will be triggered when the user LongClick one of the item from the Listview such as "Dictionary", "Book" or "Journal".
What I want to do here is, after the user has long pressed "Journal" and choose delete option, I want to Toast message "Delete Journal". If "Book" has been long pressed so it will be "Delete Book" and so on. So I need to get the String selected from setOnItemLongClick and pass the String into the Dialog Options Menu.
I'm wonder if this is possible and how? Thanks in advance for your help.
This is my code for Set Dialog Menu Options
final String[] option = new String[] { "Add", "View", "Delete" };
ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this, android.R.layout.select_dialog_item, option);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select Option");
builder.setAdapter(adapter2, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{ // TODO Auto-generated method stub
switch(which){
case 0:
Toast.makeText(getApplicationContext(), "Add", Toast.LENGTH_SHORT).show();
break;
case 1:
Toast.makeText(getApplicationContext(), "View", Toast.LENGTH_SHORT).show();
break;
case 2:
String delete="";
Toast.makeText(getApplicationContext(), "Delete " + delete, Toast.LENGTH_SHORT).show();
break;
default:
// nothing
break;
}
}
});
final AlertDialog dialog = builder.create();
This is my code for Set On Item Long Click
mylist.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener()
{
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
//show dialog menu options box
dialog.show();
return true;
}
});