我在扩展 DialogFragment 的类中构建了一个 AlertDialog:
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
super.onCreateDialog(savedInstanceState);
Intent locationTypesIntent = new Intent(getActivity(), LocationTypesRetrieverService.class);
getActivity().getApplicationContext().startService(locationTypesIntent);
itemsOnList = new CharSequence[noOfItems];
itemsChecked = new boolean[noOfItems];
for(int i=0;i<noOfItems;i++)
{
itemsOnList[i] = "Location " + i;
itemsChecked[i] = true;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Filter locations")
.setMultiChoiceItems(itemsOnList, itemsChecked,
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
System.out.println("clicked choice");
}
}
);
createdAlertDialog = builder.create();
return createdAlertDialog;
}
然后我尝试在 AlertDialog 中检索列表,并更改适配器,以更新显示的项目:
public void updateOptions(String[] optionsArray)
{
ListView list = createdAlertDialog.getListView();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity().getApplicationContext(),list.getId(),optionsArray);
list.setAdapter(adapter);
//list.invalidate();
}
我收到一个错误:
E/AndroidRuntime(9401): android.content.res.Resources$NotFoundException: 资源 ID #0x1020403 类型 #0x12 无效
到底是怎么回事???