我使用ListView
显示BaseAdapter
。我想在特定行上单击Layout
时显示ImageView
,即当我单击第1行的imageview时,布局应仅在第1行可见而不是ListView的任何其他行。我引用了this链接,但是当我单击某个特定行时,布局在其他行上也是可见的。我做了以下编码。任何人都可以帮我解决这个问题。
int prev=-1;
@Override
public View getView(final int position, View converView, ViewGroup parent) {
// TODO Auto-generated method stub
View row = converView;
holder = null;
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (row == null) {
row = inflater.inflate(R.layout.mybag_row, parent, false);
holder = new ViewHolder();
holder.tv_mybag_name = (TextView) row
.findViewById(R.id.tv_mybag_name);
holder.tv_prod_price = (TextView) row
.findViewById(R.id.tv_prod_price);
holder.tv_mybag_size = (TextView) row
.findViewById(R.id.tv_mybag_size);
holder.tv_delivery = (TextView) row.findViewById(R.id.tv_delivery);
holder.tv_mybag_price = (TextView) row
.findViewById(R.id.tv_mybag_price);
holder.imv_mybag_img = (ImageView) row
.findViewById(R.id.imv_mybag_img);
holder.imv_bag_preferences = (ImageView) row
.findViewById(R.id.imv_bag_preferences);
holder.lnr_dropdwn = (LinearLayout) row
.findViewById(R.id.lnr_dropdwn);
row.setTag(holder);
} else {
holder = (ViewHolder) row.getTag();
}
Ion.with(holder.imv_mybag_img).placeholder(R.drawable.ic_launcher)
.error(R.drawable.ic_launcher)
.load(arr_mybag.get(position).getMybag_img_url());
holder.tv_mybag_name.setText(arr_mybag.get(position).getMybag_name());
Log.i("product name in bag", arr_mybag.get(position).getMybag_name());
holder.lnr_dropdwn.setVisibility(View.GONE);
holder.imv_bag_preferences.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
holder.lnr_dropdwn
.setVisibility(position == prev ? View.VISIBLE
: View.GONE);
prev = position;
notifyDataSetChanged();
}
});
return row;
}
static class ViewHolder {
TextView tv_mybag_name, tv_prod_price, tv_mybag_size, tv_delivery,
tv_mybag_price;
ImageView imv_mybag_img, imv_bag_preferences;
LinearLayout lnr_dropdwn;
}
答案 0 :(得分:1)
在pojo类中创建一个布尔变量
private boolean isClicked;
public boolean isClicked() {
return isClicked;
}
public void setIsClicked(boolean isClicked) {
this.isClicked = isClicked;
}
//将此更改为getview
if(isClicked())
{
holder.lnr_dropdwn
.setVisibility(View.VISIBLE);
`}
else
{
holder.lnr_dropdwn
.setVisibility(View.GONE);
}`
holder.imv_bag_preferences.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
arr_mybag.get(position).setIsClicked(true);
notifydatasetchanged();
}
});