我想在片段使用的ListView。但我得到這個錯誤:致命異常:main java.lang.RuntimeException:內容具有ID屬性'android.R.id.list'的視圖不是ListView類。
我的代碼:致命異常:主要了java.lang.RuntimeException:內容有鑑於與id屬性「android.R.id.list」不是一個ListView類
我ListFragment:
public class whitelist_list extends ListFragment {
Context mContext;
@Override
public void onAttach(Activity activity) {
mContext = activity;
Log.i("Event", "onAttach called");
super.onAttach(activity);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
"Linux", "OS/2" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
return inflater.inflate(R.layout.whitelist_content, container, false);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
// Do something with the data
}
}
whitelist_list newFragment = new whitelist_list();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, newFragment)
.commit();
編輯: 解決方案:與Android聲明列表視圖:ID = 「@ ID /安卓列表」
如果您在佈局具有的ListView然後確保你有一個'機器人申報的ListView:ID =「@ ID/android:list「'id –