android – 在listitem中添加列表视图
作者:互联网
我正在使用带有列表标题的列表片段,需要在第一个列表项中添加一组列表.
我使用自定义列表适配器来加载列表项.现在对于列表项1 – 我需要在列表适配器中的列表项之上添加子视图.我该怎么办呢?我不确定可扩展列表项是否是我想在这里使用的.
我的自定义适配器的getView看起来像这样:
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
int type = getItemViewType(position);
if (convertView == null) {
holder = new ViewHolder();
switch (type) {
case TYPE_LIST_ITEM_1:
convertView = mInflater.inflate(R.id.list_item_one, null);
/* add code */
/* add another list adapter? */
break;
case TYPE_LIST_ITEM_OTHERS:
convertView = mInflater.inflate(R.layout.list_item_other, null);
/* add code for below list */
break;
}
convertView.setTag(holder);
}
else {
holder = (ViewHolder)convertView.getTag();
}
return convertView;
}
什么是最佳的实现方式,而不会丢失使用的标题视图
myListView.addHeaderView(myHeaderView);
解决方法:
如果没有重大错误,Android上的ScrollView中的ScrollView是不可能的,Google表示不这样做.您可以在列表项中包含LinearLayout(其方向设置为垂直),并手动使用addView()将视图添加到将使用布局的设置方向显示的LinearLayout.
标签:android,android-fragments,listadapter 来源: https://codeday.me/bug/20190624/1283089.html