我正在研究如何在警报对话框中添加一个arraylist。当我调用alertdialog.setItems
我得到一个无法解决此方法错误。任何人都可以看看并引导我如何解决这个问题?提前谢谢。
代码:
if(arrayListBluetoothDevices.size()<1) // this checks if the size of bluetooth device is 0,then add the
{ // device to the arraylist.
detectedAdapter.add(device.getName()+"\n"+device.getAddress());
arrayListBluetoothDevices.add(device);
final CharSequence[] items2 = {"This is here just to figure out how to get setItems to call properly"};
AlertDialog ad = new AlertDialog.Builder(context).create();
ad.setTitle("Pop up the found devices here");
ad.setItems(items2, null);
ad.setButton("Somehow set this to work when the arraylist is pressed", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//Do stuff here for OK The bottom button
}
});
ad.show();
detectedAdapter.notifyDataSetChanged();
}
答案 0 :(得分:0)
我看到了问题。在Android文档中,您正在创建AlertDialog并将其定义为AlertDialog.Builder,但setItems()方法仅在AlertDialog.Builder上有效。我会定义&#39; ad&#39;作为AlertDialog.Builder,然后从构建器创建一个AlertDialog并显示如下:
if(arrayListBluetoothDevices.size()<1) // this checks if the size of bluetooth device is 0,then add the
{ // device to the arraylist.
detectedAdapter.add(device.getName()+"\n"+device.getAddress());
arrayListBluetoothDevices.add(device);
final CharSequence[] items2 = {"This is here just to figure out how to get setItems to call properly"};
AlertDialog.Builder adb = new AlertDialog.Builder(context).create();
adb.setTitle("Pop up the found devices here");
adb.setItems(items2, null);
AlertDialog ad = adb.create();
ad.setButton("Somehow set this to work when the arraylist is pressed", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//Do stuff here for OK The bottom button
}
});
ad.show();
detectedAdapter.notifyDataSetChanged();
}
阅读文档了解详情:AlertDialog.Builder,AlertDialog