I am trying to create a onListItemClick which will show to the user a dialog with two options. Each option should call a function to execute a certain action. The error i am getting is:
Cannot refer to a non-final variable position inside an inner class defined in a different method
protected void onListItemClick(ListView l, View v, int position, long id){
final CharSequence[] items = {"Delete", "Show"};
MyPOI mpoi= myAdapter.getItem(position);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick an option");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if(items[item].equals("Delete")){
dbc.deletePOI(position);
}
}
});
AlertDialog alert = builder.create();
alert.show();
super.onListItemClick(l, v, position, id);
}
I actually manage to fix it myself. Here is my solution in case someone else has the same issue: