My question is : how can i pass item position to another class. Please see my attached code.
When i press positive button inside AlertDialog,i go to the HandleAlertDialog class , and there i delete Name by id(in database i have two variables : id and name).
I don't know how to pass id from item position to sqhelper.deleteNameByNumber(id) in HandleAlertDialog class.
Thank you for your help.
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
AlertDialog dialog = new AlertDialog.Builder(this)
.setMessage("Choose one of the options")
.setPositiveButton("Yes", new HandleAlertDialog())
.setNeutralButton("No",new HandleAlertDialog())
.setCancelable(false)
.create();
dialog.show();
return false;
}
public class HandleAlertDialog implements DialogInterface.OnClickListener {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which==-1){
sqhelper.deleteNameByNumber(**???**);
}
}
}
You can define a
idattribute inHandleAlertDialogclass (I assume this is aStringfor my example):And then use it in your
onItemLongClick: