Reputation: 55
I am using onlongitemclick
and can produce a dialog that comes up to confirm a delete, but I cannot get the listitem
position or text.
Edit: I cannot get the selectedValue string value inside of the public void onClick(DialogInterface dialog, int which) function.
lv
is my listview
object
lv.setOnItemLongClickListener(new OnItemLongClickListener()
{
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,int arg2, long arg3)
{
ListView list1 = (ListView) findViewById(android.R.id.list);
final String selectedValue = (String) list1.getItemAtPosition(arg2);
AlertDialog.Builder alertDialog = new AlertDialog.Builder(RecipeList.this);
alertDialog.setTitle("Delete");
alertDialog.setMessage(selectedValue);
alertDialog.setNegativeButton("Delete", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
obj Recipe = new obj(selectedValue, RecipeList.this);
Recipe.remove(<I need the listview item to create the object and then delete some listing in the DB, seletecValue should do this, but it does not>)
Intent intent2 = new Intent(RecipeList.this, RecipeList.class); //go to recipe list
startActivity(intent2);
} });
alertDialog.setPositiveButton("Keep", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// alertDialog.dismiss();
} });
alertDialog.show();
return true;
}
});
Upvotes: 2
Views: 3831
Reputation: 2800
arg1
is your view, you should be able to get the text from the view.
arg2
is the position.
See: http://developer.android.com/reference/android/widget/AdapterView.OnItemLongClickListener.html
Upvotes: 2