0
我是新到Android。我有一個listView
與的ListView適配器與多個可點擊項目
Image1 | Name | Image2 | Layout1 | Image3
當我點擊Image2
的Image2
的形象應該改變和Image1
的背景應該改變。
我面臨的問題是,如果在listview
中有3個可見項目,單擊第一個項目的Image2即使在4t項目的圖像中也會更改內容。如何解決這個問題,應該使用什麼方法?
我下面張貼我的代碼。
public class RecipeListAdapter extends BaseAdapter{
Context mContext;
ArrayList<CategoryDetails> categoryDetails;
View.OnClickListener clickListener;
public RecipeListAdapter(Context mContext, ArrayList<CategoryDetails> categoryDetails) {
this.mContext = mContext;
this.categoryDetails = categoryDetails;
}
@Override
public int getCount() {
return categoryDetails.size();
}
@Override
public Object getItem(int i) {
return categoryDetails.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(final int i, View convertView, ViewGroup viewGroup) {
ViewHolder holder = null;
LayoutInflater mInflater = (LayoutInflater) mContext
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.main_recycler_layout, null);
holder = new ViewHolder();
holder.recipeImage = (ImageView) convertView.findViewById(R.id.recipe_img);
holder.chowImage = (ImageView) convertView.findViewById(R.id.chow_image);
holder.recipeText = (TextView) convertView.findViewById(R.id.recipe_txt);
holder.likeBasket = (TextView) convertView.findViewById(R.id.like_bsk);
convertView.setTag(holder);
} else
holder = (ViewHolder) convertView.getTag();
holder.recipeText.setText(categoryDetails.get(i).getRecipeName());
String imageUrl = Constants.BASE_URL + categoryDetails.get(i).getRecipeImage();
Picasso.with(mContext)
.load(imageUrl)
.placeholder(R.drawable.category_default)
.into(holder.recipeImage);
holder.likeBasket.setText(categoryDetails.get(i).getBookmarkCount());
holder.chowImage.setTag(i);
final ViewHolder finalHolder = holder;
holder.chowImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
view.setVisibility(View.GONE);
finalHolder.likeBasket.setBackgroundColor(Color.parseColor("#000000"));
}
});
return convertView;
}
class ViewHolder{
ImageView recipeImage;
ImageView chowImage;
TextView recipeText;
TextView likeBasket;
}
}
請出示你的代碼。 –