[英]Add different number of TextViews to LinearLayout holder in ArrayAdapter
我有一个CustomArrayAdapter的列表视图,
想要向该listView中的LinearLayout Holder动态添加不同数量的TextView(例如,每行中的TextView列表)
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
//String menu_opcja = getItem(position);
SupleSubClass supleSubClass = getItem(position);
if (convertView==null){
convertView = inflater.inflate(R.layout.suplementacja_row, null);
holder = new ViewHolder();
holder.suplement = (TextView) convertView.findViewById(R.id.nazwa_suplementu);
holder.opis = (TextView) convertView.findViewById(R.id.descr);
holder.linearLayout = (LinearLayout)convertView.findViewById(R.id.linear_layout_test);
convertView.setTag(holder);
}
else{
holder = (ViewHolder) convertView.getTag();
}
holder.suplement.setText(supleSubClass.getName());
holder.opis.setText(supleSubClass.getDescr());
holder.linearLayout.setBackgroundColor(Color.CYAN);
return convertView;
}
private static class ViewHolder{
TextView suplement;
TextView opis;
LinearLayout linearLayout;
}
如果您知道需要多少种布局,可以使用method:
getViewTypeCount()
此方法应返回唯一布局的总数。
下一步是创建方法:
getItemViewType(int position)
这将告知给定位置要使用哪种布局。
在getView()中,仅当布局为null时才需要对其进行膨胀,并通过getItemViewType(position)确定布局
有关详细信息,请参阅本教程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.