當我嘗試使用ArrayAdaptor設置警報以顯示一組 項目時,顯示列表,但項目的字符不可見。 如果選擇該項目,則字符可見。抓住我的頭爲什麼 。欣賞任何建議。以下是模擬器的代碼和 屏幕截圖。AlertDialog不顯示來自ListAdapter的項目隱藏選項
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();
}
}
我不確定AlertDialog背景是灰色還是ArrayAdapter的字符太灰色,所以你看不到它們! – tbruyelle 2010-02-25 18:48:00