gpt4 book ai didi

android - 我可以在列表单击时关闭警报对话框吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:16:23 26 4
gpt4 key购买 nike

我有一个警报对话框,上面有一个列表,我想关闭 onlistclick 是否可以?

    AlertDialog.Builder builder = new AlertDialog.Builder(this);

final String[] Categories = SQLiteHelper.getAllCategories();//this is where i get the array for my list
ListView myList = new ListView(this);

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.alert_dialog_list_view, Categories);
myList.setAdapter(adapter);
myList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
//doing something in here and then close
}
});
builder.setTitle("Please Choose");
builder.setInverseBackgroundForced(true);
builder.setView(myList);
final Dialog dialog = builder.create();
dialog.show();
}

警报对话框运行完美,我只是不想在其中放置任何按钮。

最佳答案

如果您在 Dialog 之后定义 onItemClickListener ,您只需调用 dialog.dismiss(); onItemClick() 方法。

关于android - 我可以在列表单击时关闭警报对话框吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10106485/

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