I have a custom dialog with gridview in it. The dialog pops up when I click a textview(runs). There is a gridview in the dialog. My objective is to change value of runs textview on selecting the value from gridview and dismiss the dialog
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch (id) {
case CATEGORY_ID:
AlertDialog.Builder builder;
AlertDialog alertDialog;
// Context mContext = this;
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.gridview_cell,
(ViewGroup) findViewById(R.id.layout_root));
GridView gridview = (GridView) layout.findViewById(R.id.gridView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.text_gridview, R.id.run_cell, numbers);
gridview.setAdapter(adapter);
builder = new AlertDialog.Builder(context);
builder.setView(layout);
dialog = builder.create();
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
runs.setText(String.valueOf(position));
**dialog.cancel() or dialog.dismiss are giving me this error: 'Cannot refer to a non-final variable result inside an inner class defined in a different method'**
}
});
break;
}
return dialog;
}