I have a TextViewer Activity , that has a button, and when I click on it I want to popup an AlertDialog with list. I followed this link but it does not work (no popup). I believe the context is wrong. I used the following code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.resources);
ImageButton btnlist = (ImageButton)findViewById(R.id.list);
btnlist.setOnClickListener(new View.OnClickListener() {
public void onClick (View v){
if (Vars.bookchapter>1){
final CharSequence[] items = {"Red", "Green", "Blue"};
Context mContext = getBaseContext();
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setTitle("Pick a color");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
}
});
AlertDialog alert = builder.create();
}else{
//Nothing
}
}});
}
}