I am having a listview in my app. Each listview row expands on tap and a hidden view becomes visible but problem is that hidden view also becomes visible for many others items in the list. I know the reason for this behaviour but I don't know how to resolve it. Here is my adapter class
public class ScheduleTaskAdapter extends BaseAdapter {
Context context;
LayoutInflater layoutInflater;
// List<InterestAndLanguageBean> interestAndLanguageBeans=new ArrayList<>();
List<BirdsDataBean> imageList = new ArrayList<>();
public ScheduleTaskAdapter(Context context, List<BirdsDataBean> imagesList) {
this.context = context;
this.imageList = imagesList;
layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return imageList.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = layoutInflater.inflate(R.layout.birds_row, parent, false);
holder.iv_birds = (ImageView) convertView.findViewById(R.id.iv_bird);
holder.frameLayout = (FrameLayout) convertView.findViewById(R.id.frame_birds);
holder.linearLayout = (LinearLayout) convertView.findViewById(R.id.detail_view);
holder.imageView = (ImageView) convertView.findViewById(R.id.up);
holder.iv_video = (ImageView) convertView.findViewById(R.id.iv_video);
holder.iv_sound = (ImageView) convertView.findViewById(R.id.iv_sound);
holder.tv_short_descript = (TextView) convertView.findViewById(R.id.tv_short_descript);
holder.tv_category = (TextView) convertView.findViewById(R.id.tv_category);
holder.tv_long_description = (TextView) convertView.findViewById(R.id.tv_long_description);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Uri myUri = Uri.parse(birdsUrlList.get(position).getUrl());
Glide.with(getActivity()).load(myUri).placeholder(R.drawable.birds).into(holder.iv_birds);
holder.tv_short_descript.setText(birdsUrlList.get(position).getDescrip());
holder.tv_long_description.setText(birdsUrlList.get(position).getDescrip_larga());
holder.tv_category.setText(birdsUrlList.get(position).getNombre_cientifico());
final ViewHolder finalHolder = holder;
holder.frameLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finalHolder.linearLayout.setVisibility(View.VISIBLE);
finalHolder.iv_sound.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(birdsUrlList.get(position).getUrl_audio());
mp.prepare();
mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();
}
});
//startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(birdsUrlList.get(position).getUrl_video())));
} catch (Exception e) {
e.printStackTrace();
}
}
});
finalHolder.iv_video.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hitBirdSeenService(birdsUrlList.get(position).getIdave());
finalHolder.iv_video.setImageResource(R.drawable.eye_selected);
}
});
}
});
holder.imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finalHolder.linearLayout.setVisibility(View.GONE);
}
});
if (birdsUrlList.get(position).getFlag()==1)
{
holder.iv_video.setImageResource(R.drawable.eye_selected);
}else {
holder.iv_video.setImageResource(R.drawable.eye110);
}
//Picasso.with(context).load(myUri).placeholder(R.drawable.image).into(holder.pic);
//malevich.load(helperTaskBeanList.get(position).getImage()).into(holder.pic);
return convertView;
}
}