0
我有这个由Web服务器的json数据填充的ListActivity,但突然间我想尝试在我的应用程序上使用ViewPager。无法添加窗口 - 标记null不适用于来自ListFragment的应用程序
看起来好像ListActivity和ListFragment具有几乎相同的功能。所以我所做的就是将代码复制粘贴到ListFragment,但我已经改变了一些代码来摆脱错误。
我所做的就是把所有的代码从的onCreate(ListActivity)到onCreateView(ListFragment)是这样的:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_movies, container, false);
examinationList = new ArrayList<HashMap<String, String>>();
ListView lv = getListView();
new GetContacts().execute();
return rootView;
}
创建尚未创建例外的内容视图。所以我所做的就是创建一个onViewCreated方法和onCreateView删除所有不必要的代码,并将其转移到onViewCreated
@Override
public void onViewCreated (View view, Bundle savedInstanceState) {
examinationList = new ArrayList<HashMap<String, String>>();
ListView lv = getListView();
new GetContacts().execute();
}
是删除内容视图尚未创建例外,但现在另一个异常出现,我解决不了。
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
EDITED
fragment_movies.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<!-- Main ListView
Always give id value as list(@android:id/list)
-->
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
也许你在做这个onActivityCreated方法而不是onViewCreated – 2015-01-20 20:57:06
我试过在onActivityCreated方法上添加它,它仍然给我相同的异常。 – user3566976 2015-01-21 00:31:42
是否尝试评论新的GetContacts()。execute();? – 2015-01-21 00:57:59