我有一个内部类来创建和显示一个简单的列表对话框。
private static class DisplayListDialogFragment extends DialogFragment
{
List<String> list;
OnClickListener clickListener;
private static DisplayListDialogFragment newInstance(List<String> list, String title, OnClickListener clickListener)
{
DisplayListDialogFragment dldf = new DisplayListDialogFragment();
dldf.list = (List<String>)list;
dldf.clickListener = clickListener;
Bundle bundle = new Bundle();
bundle.putString("title", title);
dldf.setArguments(bundle);
return dldf;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
ArrayAdapter<String> ad = new ArrayAdapter<String>(getActivity(), R.id.simpleListItem, this.list);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string._select_display)
.setSingleChoiceItems(ad, 1, this.clickListener);
return builder.create();
}
}
引用的资源在字符串文件中声明
<string name="_select_display">Select Display</string>
和一个名为 simple_list.xml 的小文件
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/simpleListItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
该应用程序在线路资源膨胀器深处的某处爆炸
return builder.create();
堆栈跟踪是
11-12 17:21:01.664: E/AndroidRuntime(1335): android.content.res.Resources$NotFoundException: Resource ID #0x7f040052 type #0x12 is not valid
11-12 17:21:01.664: E/AndroidRuntime(1335): at android.content.res.Resources.loadXmlResourceParser(Resources.java:1874)
11-12 17:21:01.664: E/AndroidRuntime(1335): at android.content.res.Resources.getLayout(Resources.java:731)
11-12 17:21:01.664: E/AndroidRuntime(1335): at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
11-12 17:21:01.664: E/AndroidRuntime(1335): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
11-12 17:21:01.664: E/AndroidRuntime(1335): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
资源 ID 在 R.java 中定义为
public static final int simpleListItem=0x7f040052
(即上面simple_list.xml文件中声明的TextView)
任何人都可以看到有什么问题吗?我现在正在挠头。
谢谢
安德鲁