试图将标题放在这样的 ListFragment 中
@Override
public View onCreateView(org.holoeverywhere.LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View listRoot = inflater.inflate(R.layout.list, null);
headerView = inflater.inflate(R.layout.header);
return listRoot;
}
在 onActivityCreated
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setEmptyText("No Contacts");
setHasOptionsMenu(true);
ListView listView = getListView();
//String headerData = "ZZZZZZZZ";
if(headerView != null) listView.addHeaderView(headerView);
String[] from = {TableMetaData.NAME};
int[] to = {R.id.menu_name};
customListAdapter = new ContactListAdapter(getActivity(), R.layout.menu_row,
null, from, to, 0);
setListAdapter(customListAdapter);
setListShown(false);
getLoaderManager().initLoader(0, null, this).forceLoad();
}
我在 Logcat 中收到以下错误
02-04 05:53:09.287: E/AndroidRuntime(22767): FATAL EXCEPTION: main
02-04 05:53:09.287: E/AndroidRuntime(22767): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.abc.xyz/com.abc.xyz.mnp.Mnp}: java.lang.IllegalStateException: Can't be used with a custom content view
02-04 05:53:09.287: E/AndroidRuntime(22767): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
02-04 05:53:09.287: E/AndroidRuntime(22767): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)
02-04 05:53:09.287: E/AndroidRuntime(22767): at android.app.ActivityThread.access$2300(ActivityThread.java:126)
02-04 05:53:09.287: E/AndroidRuntime(22767): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038)
02-04 05:53:09.287: E/AndroidRuntime(22767): at android.os.Handler.dispatchMessage(Handler.java:99)
02-04 05:53:09.287: E/AndroidRuntime(22767): at android.os.Looper.loop(Looper.java:123)
02-04 05:53:09.287: E/AndroidRuntime(22767): at android.app.ActivityThread.main(ActivityThread.java:4633)
02-04 05:53:09.287: E/AndroidRuntime(22767): at java.lang.reflect.Method.invokeNative(Native Method)
02-04 05:53:09.287: E/AndroidRuntime(22767): at java.lang.reflect.Method.invoke(Method.java:521)
02-04 05:53:09.287: E/AndroidRuntime(22767): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
02-04 05:53:09.287: E/AndroidRuntime(22767): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
02-04 05:53:09.287: E/AndroidRuntime(22767): at dalvik.system.NativeStart.main(Native Method)
对我来说,它看起来像是在要求我删除setEmptyText("No Contacts");
和删除setListShown(false);
setListShown(true);
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
我的问题
为什么会出现这个错误?如何避免/规避这个错误?