我目前有一个ListFragment,我从OnCreateView()
(包含在下面)中返回一个自定义ListView。
我遇到的问题是当视图中只有少数项目时,您可以在后台看到进度指示器。 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
答案 0 :(得分:2)
来自ListFragment does not accept my layout
似乎这是谷歌的一个错误。这里有一些建议: http://code.google.com/p/android/issues/detail?id=21742
答案 1 :(得分:-1)
您可以通过
隐藏指标getView().findViewById(16711682).setVisibility(View.GONE);
//16711682 is the variable mProgressContainer's id.
在视图初始化后将其放入,就像在onActivityCreated
方法中