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() ...
最佳答案
你需要使用
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);
关于java - 从另一个 xml 布局添加 ListView 时出现 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18249095/