gpt4 book ai didi

android - AlertDialog 不显示来自 ListAdapter 隐藏选项的项目

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

当我尝试使用 ArrayAdaptor 设置警报以显示一组项,显示列表但项的字符不可见。如果选中该项目,则字符可见。抓挠我在想为什么。感谢任何建议。下面是代码和模拟器的截图。

public class MessageTest extends Activity implements 
View.OnClickListener {
public final static String debugTag = "MessageDemo::";
Button alert;
Button toast;
String[] items={"item1", "item2", "item3", "item4", "item5" };


@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);


setContentView(R.layout.message);


alert=(Button)findViewById(R.id.alert);
alert.setOnClickListener(this);
}


public void onClick(View view) {
if (view==alert) {
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_single_choice, items);


new AlertDialog.Builder(this)
.setTitle("MessageTest")
.setSingleChoiceItems(aa, 0, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dlg, int which) {
Log.d(MessageDemo.debugTag,
"DialogInterface.OnClickListener::onClick() is called -> which =
"+which);
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
Log.d(MessageDemo.debugTag, "OK button is clicked -> sumthin
= "+sumthin);
}
})
.setNeutralButton("Close", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
Log.d(MessageDemo.debugTag, "Close button is clicked ->
sumthin = "+sumthin);
// do nothing -- it will close on its own
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dlg, int sumthin) {
Log.d(MessageDemo.debugTag, "Cancel button is clicked ->
sumthin = "+sumthin);
}
})
.show();
}
}

最佳答案

我知道我回答的有点晚了,但我遇到了同样的问题,我通过简单的改变解决了它

ArrayAdapter<String> aa = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, items);

ArrayAdapter<String> aa = new ArrayAdapter<String>(this, android.R.layout.select_dialog_singlechoice, items);

希望对大家有所帮助。

关于android - AlertDialog 不显示来自 ListAdapter 隐藏选项的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2336427/

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