[英]Android layoutinflater on listview not working
我正在創建一個用httpview數組填充的listview的類,我之前做過,代碼還可以。 但是,當我安裝應用程序時,我在LogCat中得到了白色的屏幕(沒有強制關閉),我沒有任何錯誤消息。 LayoutInflater無法設置activity_main。
這是我在其中聲明列表視圖的activity_main。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@color/black_cool" >
<ListView
android:id="@+id/custom_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#00000000"
android:dividerHeight="1dp" />
</FrameLayout>
ListView
對象位於list_row_layout.xml
無需發布它,一切正常。
public class MainActivity extends Activity {
public ArrayList<FeedItem> feedList;
public ListView feedListView;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_main, container, false);
String url = "...";
new DownloadFilesTask().execute(url);
return rootView;
}
public void updateList() {
feedListView= (ListView) findViewById(R.id.custom_list);
feedListView.setAdapter(new CustomListAdapter(this, feedList));
}
}
.... json類和其他...
應該是什么問題? 我嘗試擴展一個Fragment
但結果相同。 我嘗試添加onCreate
和setContentview
但沒有幫助我。
擴展活動覆蓋onCreate
。 在onCreate
初始化listview
public ListView feedListView;
@Override
public void onCreate(bundle savedInstanceState)
{
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main);
feedListView= (ListView) findViewById(R.id.custom_list);
new DownloadFilesTask().execute(url);
}
試試這個extend Activity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
feedListView= (ListView) findViewById(R.id.custom_list);
String url = "...";
new DownloadFilesTask().execute(url);
feedListView.setAdapter(new CustomListAdapter(this, feedList));
}
並嘗試使用此extend Fragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_main, container, false);
feedListView= (ListView) rootView.findViewById(R.id.custom_list);
String url = "...";
new DownloadFilesTask().execute(url);
feedListView.setAdapter(new CustomListAdapter(this, feedList));
return rootView;
}
改變這條線
feedListView= (ListView) findViewById(R.id.custom_list);
入。
feedListView= (ListView) getView().findViewById(R.id.custom_list);
這是片段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.