[英]How to inflate a ListView into a LinearLayout
我已经通过使用ArrayAdapter
创建了一个ListView
,其中包含了一个项目列表。 我想将此ListView
添加到另一个LinearLayout
,如果有人单击它,将显示项目列表。 可以实现吗? 请任何人帮助我。
您必须将OnClickListener添加到LinearLayout中,然后在Listener中添加它:
LinearLayout lr = (LinearLayout)findViewById(R.id.yourLinearlayout);
lr.addView(Listview);
所以我想您只需要从Iten的文本创建一个TextView,然后将其添加到LinearLayout中即可:
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// String define above
strText = l.getItemAtPosition(position).toString();
LinearLayout lr = (LinearLayout)findViewById(R.id.yourLinearlayout);
//Create a textview
TextView tv = new TextView(getActivity());
//Set the text of the TextView with the Item Text
tv.setText(strText);
//Add it to your ListView
lr.addView(Listview);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.