gpt4 book ai didi

android - 自定义 AlertDialog 未显示

转载 作者:行者123 更新时间:2023-11-29 15:33:13 26 4
gpt4 key购买 nike

我有一个 TextViewer Activity,它有一个按钮,当我点击它时,我想弹出一个带有列表的 AlertDialog。我跟着这个link但它不起作用(没有弹出窗口)。我认为上下文是错误的。我使用了以下代码:

    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
}
}});
}
}

最佳答案

您还没有调用 show()方法。这样做:

AlertDialog alert = builder.create();
alert.show();

关于android - 自定义 AlertDialog 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3160231/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com