![](/img/trans.png)
[英]How can i add favourite (CheckBox/ToggleButton/ImageView) to my ListView?
[英]How can I add an ImageView as a ListView Header?
任何人都可以帮我找到如何将ImageView作为标题添加到ListView?
我的代码在这里:
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View snapshot = inflater.inflate(R.layout.map_snapshot, null);
ListView channelsList = (ListView) findViewById(R.id.channelsList);
channelsList.addHeaderView(snapshot);
到现在为止它什么也没显示
尝试通过父(ListView)作为参数来扩展标题视图:
ListView channelsList = (ListView) findViewById(R.id.channelsList);
View snapshot = inflater.inflate(R.layout.map_snapshot, channelList, false);
然后,只需将其添加到ListView:
channelsList.addHeaderView(snapshot);
您可以使用CommonsWare MergeAdapter或SectionedListAdapter 。 使用此库,您可以在Listview
使用任何View
as Header。 有关详细信息,请参阅此SO问题并接受答案。
尝试:
ListView channelsList = (ListView) findViewById(R.id.channelsList);
LayoutInflater inflater = getLayoutInflater();
ViewGroup header = (ViewGroup)inflater.inflate(R.layout.map_snapshot, channelsList , false);
channelsList .addHeaderView(header, null, false);
在布局map_snapshot中,您必须具有父布局,因为我已采用线性布局同样采用它。
ListView channelsList = (ListView) findViewById(R.id.channelsList);
LinearLayout headerView = (LinearLayout) getLayoutInflater().inflate(R.layout.map_snapshot, null);
listView.addHeaderView(headerView);
如果要在布局中添加视图:
TextView mUsername=(TextView) headerView.findViewById(R.id.user_name);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.