0
我想爲7th, 14th, 21th
位置添加新的imageview
項目。在Android中滾動時出現第二種類型的項目,不同項目列表視圖示例
當我添加新項目併爲其創建新的佈局類型時,它不能很好地工作。
當滾動批次imageview
(類型2)項目出現在不同的位置。
我該如何解決這個問題,是我的錯誤?
(我只是嘗試了第七的位置在這個代碼來解決問題的滾動)
public class MyAdapter extends BaseAdapter{
MyFragmentManager mFragmentManager;
List<Tier3Category>list;
Context context;
ListView myList;
OneriDetail myObj;
Tier3Category obj;
public MyAdapter(Context context, List<Tier3Category> list, MyFragmentManager mFragmentManager,
ListView myList, int type) {
super();
this.mFragmentManager = mFragmentManager;
this.list = list;
if(list.size()>1)
list.add(7,new Tier3Category("", "", "", "", "", "", "", "", "", "", "", "", "", false, false, false, "", "", "", ""));
Log.w("", list.size()+"asd");
this.context = context;
this.myList = myList;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public Tier3Category getItem(int position) {
if (getCount()>0){
return list.get(position);
}
else{
return null;
}
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder1 vh ;
final ViewHolder2 vh2;
if(position!=7){
try {
if (convertView==null){
vh = new ViewHolder1();
convertView = LayoutInflater.from(context).inflate(
R.layout.adapter_oneri_list, parent, false);
vh.title = (TextView) convertView.findViewById(R.id.list_title);
convertView.setTag(vh);
}
else{
vh = (ViewHolder1)convertView.getTag();
}
convertView.setTag(vh);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else {
try {
if (convertView==null){
vh2 = new ViewHolder2();
convertView = LayoutInflater.from(context).inflate(R.layout.adapter_adv_item, parent,false);
vh2.adv_photo = (ImageView) convertView.findViewById(R.id.adv_image);
convertView.setTag(vh2);
}
else{
vh2 = (ViewHolder2)convertView.getTag();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return convertView;
}
public class ViewHolder1{
TextView comment_count , like_count , follow_count , username , time , title , content, location , categoryname;
RoundedImageView sugg_photo;
RoundedImageView user_photo;
RelativeLayout threedot;
ImageView likeIcon , commentIcon , followIcon;
}
public class ViewHolder2{
ImageView adv_photo;
}
}
非常感謝您,YOU ROCK。這工作:) –