在我的应用程序中,我使用基本适配器在列表视图上显示大陆。我想在列表上显示2个文本视图和1个图像视图。图像视图显示在标记条件下。第一次显示所有内容正确。但是,如果我在我的列表中滚动我们的意外行为。图像视图显示在标志为false的行上。下面是我的代码... 请帮帮我!!!!
public class MyAdapter extends BaseAdapter
{
private Context context;
Views viewsList;
private ArrayList<Views> selectedItems = new ArrayList<Views>();
public MyAdapter(Context c, int textViewResourceId,
ArrayList<Views> list) {
super();
this.context=c;
this.selectedItems=list;
}
public int getCount() {
return selectedItems.size();
}
public Object getItem(int position) {
return selectedItems.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
viewsList=selectedItems.get(position);
myAdapter.notifyDataSetChanged();
View v=convertView;
ImageView tipImageView;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
TextView bTitle,textVies,likeView;
if (v == null) {
v = inflater.inflate(R.layout.tips_viwes_and_like_gui, null);
bTitle = (TextView) v.findViewById(R.id.textname);
bTitle.setText(viewsList.getName());
if(viewsList.getContaisImage().contains("1"))
{
tipImageView=(ImageView)v.findViewById(R.id.setImageId);
tipImageView.setImageResource(R.drawable.tip_image);
}
else if(viewsList.getContaisImage().contains("0"))
{
tipImageView=null;
}
textVies = (TextView) v.findViewById(R.id.textviews);
textVies.setText("Views :"+viewsList.getViewsId());
likeView=(TextView) v.findViewById(R.id.textLike);
likeView.setText("Like :"+viewsList.getLike());
}
return v;
}
}
答案 0 :(得分:1)
这是非常常见的问题,您必须编写此行的else部分 试试这种方式
public View getView(int position, View convertView, ViewGroup parent) {
viewsList=selectedItems.get(position);
myAdapter.notifyDataSetChanged();
View v=converView;
ImageView tipImageView;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
TextView bTitle,textVies,likeView;
if (v == null) {
v = inflater.inflate(R.layout.tips_viwes_and_like_gui, null);
bTitle = (TextView) v.findViewById(R.id.textname);
textVies = (TextView) v.findViewById(R.id.textviews);
likeView=(TextView) v.findViewById(R.id.textLike);
tipImageView=(ImageView)v.findViewById(R.id.setImageId);
}
bTitle.setText(viewsList.getName());
likeView.setText("Like :"+viewsList.getLike());
textVies.setText("Views :"+viewsList.getViewsId());
tipImageView.setImageResource(R.drawable.tip_image);
if(viewsList.getContaisImage().contains("0")){
tipImageView.setVisibile(ImageView.GONE);
}else{
tipImageView.setVisibile(ImageView.VISIBLE);
}
return v;
}