我目前有一个 ListFragment,我从中返回一个自定义 ListView OnCreateView()
(包括在下面)。
我遇到的问题是当视图中只有几个项目时,您可以在后台看到进度指示器。setListShown(true)
隐藏进度指示器,但在返回自定义视图时会导致 IllegalStateException。
关于隐藏进度指示器的方法有什么想法吗?
@Override
public ListView onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
ListView lv = new ListView(this.getActivity());
lv.setId(android.R.id.list);
lv.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
lv.setStackFromBottom(true);
return lv;
}
编辑:我也尝试过膨胀视图,但它返回相同的 IllegalStateException。
@Override
public void onActivityCreated (Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
setListShown(true);
}
@Override
public ListView onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
ListView lv = (ListView) inflater.inflate(R.layout.chat_fragment, container, false);
lv.setId(android.R.id.list);
return lv;
}
08-02 12:58:19.552: E/AndroidRuntime(27844): FATAL EXCEPTION: main
08-02 12:58:19.552: E/AndroidRuntime(27844): java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.wisc.ACHESS/edu.wisc.ACHESS.ChatMessageActivity}: java.lang.IllegalStateException: Can't be used with a custom content view
08-02 12:58:19.552: E/AndroidRuntime(27844): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
08-02 12:58:19.552: E/AndroidRuntime(27844): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-02 12:58:19.552: E/AndroidRuntime(27844): at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-02 12:58:19.552: E/AndroidRuntime(27844): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-02 12:58:19.552: E/AndroidRuntime(27844): at android.os.Handler.dispatchMessage(Handler.java:99)
08-02 12:58:19.552: E/AndroidRuntime(27844): at android.os.Looper.loop(Looper.java:137)
08-02 12:58:19.552: E/AndroidRuntime(27844): at android.app.ActivityThread.main(ActivityThread.java:4745)
08-02 12:58:19.552: E/AndroidRuntime(27844): at java.lang.reflect.Method.invokeNative(Native Method)
08-02 12:58:19.552: E/AndroidRuntime(27844): at java.lang.reflect.Method.invoke(Method.java:511)
08-02 12:58:19.552: E/AndroidRuntime(27844): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-02 12:58:19.552: E/AndroidRuntime(27844): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-02 12:58:19.552: E/AndroidRuntime(27844): at dalvik.system.NativeStart.main(Native Method)
08-02 12:58:19.552: E/AndroidRuntime(27844): Caused by: java.lang.IllegalStateException: Can't be used with a custom content view
08-02 12:58:19.552: E/AndroidRuntime(27844): at android.support.v4.app.ListFragment.setListShown(ListFragment.java:282)
08-02 12:58:19.552: E/AndroidRuntime(27844): at android.support.v4.app.ListFragment.setListShown(ListFragment.java:258)
08-02 12:58:19.552: E/AndroidRuntime(27844): at edu.wisc.ACHESS.fragments.ChatFragment.onViewCreated(ChatFragment.java:19)
08-02 12:58:19.552: E/AndroidRuntime(27844): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:885)
08-02 12:58:19.552: E/AndroidRuntime(27844): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1083)
08-02 12:58:19.552: E/AndroidRuntime(27844): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:635)
08-02 12:58:19.552: E/AndroidRuntime(27844): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1431)
08-02 12:58:19.552: E/AndroidRuntime(27844): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:523)
08-02 12:58:19.552: E/AndroidRuntime(27844): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163)
08-02 12:58:19.552: E/AndroidRuntime(27844): at android.app.Activity.performStart(Activity.java:5018)
08-02 12:58:19.552: E/AndroidRuntime(27844): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2032)
08-02 12:58:19.552: E/AndroidRuntime(27844): ... 11 more