我正在尝试更改ListView CustomAdapter中的ImageButton image.ImageButton.When单击该ImageButton更改ImageButton的图像。我尝试这样做。但是没有效果。
private int[] mIcons = { R.drawable.like_grey, R.drawable.dislike_grey };
private int[] mSelectedIcons = { R.drawable.like_selected, R.drawable.dislike_selected};
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
holder = new ViewHolder();
convertView = mLayoutInflater.inflate(R.layout.moments_custom_screen, null);
holder.mLikeBtn = (ImageButton) convertView.findViewById(R.id.like_btn);
holder.mDisLikeBtn =(ImageButton)convertView.findViewById(R.id.dislike_btn);
holder.mLikeBtn.setImageResource(mIcons[0]);
holder.mDisLikeBtn.setImageResource(mIcons[1]);
holder.mLikeBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
notifyDataSetChanged();
holder.mLikeBtn.setImageResource(mSelectedIcons[0]);
holder.mDisLikeBtn.setClickable(true);
}
});
holder.mDisLikeBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
holder.mLikeBtn.setImageResource(mIcons[0]);
holder.mDisLikeBtn.setImageResource(mSelectedIcons[1]);
holder.mDisLikeBtn.setClickable(false);
}
});