我想在列表視圖中添加動態標頭,即列表視圖標頭的動態數據將在加載列表視圖時從解析的信息中獲得。在列表視圖中使用getItemType
請閱讀下面的我的方案。必須瞭解我的問題。
在這裏,我這樣做使用getItemType爲列表視圖的位置0。
@Override public View getView(final int position,View convertView,ViewGroup parent){ ViewHolder holder; if(convertView == null){
int type = getItemViewType(position);
if(type==TYPE_HEADER){
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.my_basket_small_item, parent,false);
convertView.setTag(holder);
}else{
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.my_basket_small_item, parent,false);
holder.tv_price = (TextView)convertView.findViewById(R.id.tv_price);
holder.tv_distance = (TextView)convertView.findViewById(R.id.tv_distance);
holder.img_brandLogo = (ImageView)convertView.findViewById(R.id.img_brandlogo_top);
holder.img_beerCanLogo = (ImageView)convertView.findViewById(R.id.img_beerCan);
holder.click4map = (Button)convertView.findViewById(R.id.btn_click_for_map);
holder.offers = (Button)convertView.findViewById(R.id.btn_my_basket_offers);
}
}
else{
holder = (ViewHolder) convertView.getTag();
}
return convertView;
我的問題是,我想顯示固定頭動態數據加列表視圖行(arraylist大小總數)。 現在它正在工作少一行,因爲一行被列表視圖標題佔據。
方案: 例如4列表視圖行未來(無頭) 當我使用頭,4再次行來了,我只是想,當我使用頭,1頭加4行應該來。
希望你明白。
感謝
但頭部的數據應該是動態的,我必須改變它在適配器類 –
發佈您的完整適配器。我沒有看到你設置了你發佈的任何數據。但重寫getCount應該適用於你的情況 –