I need a little bit of help: I have a listview with a custom list item and a viewholder. The code I copied represents the adapter I am using but a simplier version. For the sake of simplicity, lets say I have an ImageView and a LinearLayout inside every single ListView item. I would like to apply a setOnClickListener on every item which should do the following: change the visibility of the LinearLayout inside ANOTHER item, so in another position (e.g. always the 5th). Obviously if i call holder.rl.setvisibility(..), it changes the visibility in the same position. I assume I can somehow reference to the item I need to change but I am not sure. How could you guys do this?
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context mContext) {
this.mContext = mContext;
}
@Override
public int getCount() {
return bImageList.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
View view = convertView;
if (view == null) {
view = getActivity().getLayoutInflater().inflate(R.layout.discover_item_layout_my, parent, false);
holder = new ViewHolder();
assert view != null;
holder.itemImage = (ImageView) view.findViewById(R.id.main_discover_listitem_itemimage);
holder.ll = (LinearLayout) view.findViewById(R.id.anim_rl);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
holder.ll.setVisibility(View.VISIBLE);
holder.itemImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//need to set holder.ll visibility to GONE but in another position
}
});
return view;
}
class ViewHolder {
ImageView itemImage;
LinearLayout ll;
}
}
Thank you guys!
0 comments:
Post a Comment