我有一个包含自定义行的自定义适配器。在这些自定义行中,我有一个imageview,我必须根据某些东西调整其图像资源。没关系。但是当在第一行中更改此图像视图图像资源时,它会影响在转换视图之后的行不是空的'。在我第四排后的情况。我知道它从convertview引用并快速构建,但我怎样才能克服它? (holder.image3)
KanalHolder holder = null;
final int pozisyon = position;
Object currentKanal = getItem(position);
Kanal kanal = (Kanal) currentKanal;
if(convertView==null) {
holder = new KanalHolder();
if (kanal.official) {
convertView = lala.inflate(R.layout.officialkanal, null);
holder.image2 = (ImageView) convertView.findViewById(R.id.imageView5);
holder.image3 = (ImageButton) convertView.findViewById(R.id.button7);
holder.tv3 = (TextView) convertView.findViewById(R.id.textView4);
holder.tv4 = (TextView) convertView.findViewById(R.id.textView8);
holder.buton1 = (ImageButton) convertView.findViewById(R.id.button7);
holder.buton2 = (ImageButton) convertView.findViewById(R.id.button8);
holder.buton3 = (ImageButton) convertView.findViewById(R.id.imageButton7);
Log.i("tago", "tagtagatagtagtagatg");
}
if (!kanal.official) {
convertView = lala.inflate(R.layout.normalkanal, null);
holder.image1 = (ImageView) convertView.findViewById(R.id.imageView5);
holder.tv1 = (TextView) convertView.findViewById(R.id.textView4);
holder.tv2 = (TextView) convertView.findViewById(R.id.textView8);
Log.i("tago", "tagtagtag");
}
convertView.setTag(holder);
}else{
holder = (KanalHolder)convertView.getTag();
}
if(kanal.official){
Drawable a = ContextCompat.getDrawable(context , R.drawable.taylanprof);
holder.image2.setBackground(a);
Log.i("tago" , "kanaladapter position = " + channelbaba.get(position).getLikedurumu());
if(channelbaba.get(position).getLikedurumu()== 1){
holder.image3.setImageResource(R.mipmap.heartson);
}
holder.tv3.setText(channelbaba.get(position).getKanaladi());
holder.image2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
kanaladi = channelbaba.get(position).getKanaladi();
Log.i("tago", kanaladi);
kEE = new KanalaElemanEkle();
kEE.execute(kanaladi);
Intent intent = new Intent(context, GrupSohbeti.class);
intent.putExtra("kanaladi", kanaladi);
context.startActivity(intent);
}
});
final ImageButton image1 = holder.image3;
holder.image3.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
image1.setImageResource(R.mipmap.heartson);
image1.setClickable(false);
Log.i("tago" , "butona tıklanıldı");
String channelid = channelbaba.get(pozisyon).getId();
Log.i("tago" , "channel id= " + channelid);
officialkanalilikela(channelbaba.get(pozisyon).getId());
}
});
}
if(!kanal.official){
holder.image1.setImageResource(R.mipmap.apoprof);
holder.tv1.setText(channelbaba.get(position).getKanaladi());
holder.image1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
kanaladi = channelbaba.get(pozisyon).getKanaladi();
Log.i("tago" , kanaladi);
kEE = new KanalaElemanEkle();
kEE.execute(kanaladi);
Intent intent = new Intent(context , GrupSohbeti.class);
intent.putExtra("kanaladi" , kanaladi);
context.startActivity(intent);
}
});
}
return convertView;
}
答案 0 :(得分:0)
我只想到解决方案,对不起快速提问。对于新手来说,这需要重新安排:
if(channelbaba.get(position).getLikedurumu()== 1){
holder.image3.setImageResource(R.mipmap.heartson);
Log.i("tago" , "likedurumu1");
}else{
holder.image3.setImageResource(R.mipmap.heartsonn);
Log.i("tago", "likedurumu2");
}
final ImageButton image1 = holder.image3;
holder.image3.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
channelbaba.get(pozisyon).setLikedurumu(1);
image1.setImageResource(R.mipmap.heartson);
image1.setClickable(false);
Log.i("tago" , "butona tıklanıldı");
String channelid = channelbaba.get(pozisyon).getId();
Log.i("tago" , "channel id= " + channelid);
officialkanalilikela(channelbaba.get(pozisyon).getId());
}
});