1
feedLayout = new LinearLayout(this);
feedLayout.setOrientation(LinearLayout.VERTICAL);
//LayoutInflater inflater = (LayoutInflater)  getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = getLayoutInflater().inflate(R.layout.list_feeds, feedLayout, false);
lstFeeds = (ListView) v.findViewById(R.id.listfeeds);
lstFeeds.setAdapter(new FeedsAdapter(this, android.R.layout.simple_list_item_1, lista));
feedLayout.addView(lstFeeds);

日志猫:

IllegalStateException:
The specified child already has a parent you must call removeChild() ...
4

2 回答 2

2

你需要使用

feedLayout.removeAllViews();

feedLayout.addView(v);

编辑 :

feedLayout = new LinearLayout(this);
feedLayout.setOrientation(LinearLayout.VERTICAL);
//LayoutInflater inflater = (LayoutInflater)  getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = getLayoutInflater().inflate(R.layout.list_feeds, feedLayout, false);
lstFeeds = (ListView) v.findViewById(R.id.listfeeds);
lstFeeds.setAdapter(new FeedsAdapter(this, android.R.layout.simple_list_item_1, lista));
feedLayout.addView(v);
于 2013-08-15T08:41:56.567 回答
0

更好的做法是使自定义适配器扩展基本适配器并在 getView() 方法中扩展布局。

于 2013-08-15T08:44:35.110 回答