ListViewの特定の行で1つの項目(ImageView)を変更したいとします。今私はそれを変更するにはonItemClickListener
ビューを提供して変更しようとしました。それも動作します!ListViewの1つの要素を変更する
しかし、何とか上下にスクロールすると、他のリストビューの行も変更されます。私は問題について何かを見つけた"view recycling"
しかし、私は本当にそれのための解決策を見つけませんでした。
誰かが役に立ちますか?
EDIT:ここ いくつかのコード:
マイリスナー:
LV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
...
updateEQAnimation(position,view);
...
}
それを
private void updateEQAnimation(int index, View view){
ColorStateList sColorStatePlaying;
ColorStateList sColorStateNotPlaying;
sColorStatePlaying = ColorStateList.valueOf(context.getResources().getColor(R.color.colorPrimary));
if(view == null)
return;
AnimationDrawable animation = (AnimationDrawable) ContextCompat.getDrawable(context, R.drawable.anim_current_song);
ImageView EQ_ANIM = (ImageView) view.findViewById(R.id.imageView_eq_animation);
EQ_ANIM.setVisibility(View.VISIBLE);
EQ_ANIM.setImageDrawable(animation);
EQ_ANIM.setImageTintList(sColorStatePlaying);
animation.start();}
GetViewメソッドに変更する必要がある関数:
@Override
public View getView(int position, View view, ViewGroup parent) {
View rview = view;
holder = null;
if (rview == null)
{
LayoutInflater inflater = context.getLayoutInflater();
rview= inflater.inflate(R.layout.row_song, null, true);
holder = new ViewHolder(rview);
rview.setTag(holder);
}
else
{
holder = (ViewHolder) rview.getTag();
}
mArtLoader.loadBitmap(AL_songlist.get(position).getAlbumArtPath(), holder.imgAlbumart);
holder.txtTitle.setText(AL_songlist.get(position).getTitle());
holder.txtArtist.setText(AL_songlist.get(position).getArtist());
if(Main.songService.svc_mpcontroller != null && Main.global_music_controller != null) {
if (AL_songlist.get(position).getID() == Main.global_music_controller.get_current_id()) {
ColorStateList sColorStatePlaying;
ColorStateList sColorStateNotPlaying;
sColorStatePlaying = ColorStateList.valueOf(context.getResources().getColor(R.color.colorPrimary));
AnimationDrawable animation = (AnimationDrawable) ContextCompat.getDrawable(context, R.drawable.anim_current_song);
holder.imgEQAnimation.setVisibility(View.VISIBLE);
holder.imgEQAnimation.setImageDrawable(animation);
holder.imgEQAnimation.setImageTintList(sColorStatePlaying);
animation.start();
}
}
return rview;
}
を
にelseステートメントを追加する必要があります次に、あなたのアダプタの
getView
に次のことを行うことができます変更してから、そのIDをさらに操作してください。 –私のコードは現在 –
に編集されています。 getItemId heint a inti int geri veriyo。 –