自定义AlertDialog没有显示
问题描述:
我有一个TextViewer Activity,它有一个按钮,当我点击它时,我想弹出AlertDialog列表。我跟着这个link,但它不工作(没有弹出)。我相信背景是错误的。 我用下面的代码:自定义AlertDialog没有显示
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
}
}});
}
}
这是令人尴尬:( 感谢 – OkyDokyman 2010-07-01 17:46:04
那天正好最好的程序员也。 – Cristian 2010-07-01 18:00:51