listview recyclerview问题?

时间:2014-11-17 10:17:11

标签: android android-listview android-view

我有一个listview,其中我有一个视图,我已经设置了一个可见性gone.now按钮点击这个listview的一个子元素我想显示这个视图,但它显示在多个位置listview。我知道这是由于回收的视图,但我无法为它实现解决方案。有人有建议,这是我的代码

if(convertView == null)
    {
        convertView = inflator.inflate(R.layout.fragment_open_orders_row, null);
        fulfilledView = new FulFilledOrdersHolder();

        fulfilledView.title = (TextView) convertView.findViewById(R.id.tv_open_order_title);
        fulfilledView.order_datetime = (TextView) convertView.findViewById(R.id.tv_open_order_datetime);
        fulfilledView.customer_address = (TextView) convertView.findViewById(R.id.tv_open_order_address);
        fulfilledView.customer_name = (TextView) convertView.findViewById(R.id.tv_open_order_name);
        fulfilledView.product_price = (TextView) convertView.findViewById(R.id.tv_open_order_price);

        fulfilledView.product_image = (ImageView) convertView.findViewById(R.id.imv_open_orders);

        fulfilledView.details = (Button) convertView.findViewById(R.id.button_open_orders_details);
        fulfilledView.call = (Button) convertView.findViewById(R.id.button_open_orders_call);

        fulfilledView.slide = (RelativeLayout) convertView.findViewById(R.id.sliding);
        fulfilledView.slide.setVisibility(View.GONE);
        convertView.setTag(fulfilledView);
    }
    else
    {
    fulfilledView = (FulFilledOrdersHolder) convertView.getTag();
    }

    fulfilledView.title.setText(values.get(position).getTitle());
    fulfilledView.order_datetime.setText(values.get(position).getOrder_datetime());


    fulfilledView.details.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

                fulfilledView.slide.setVisibility(View.VISIBLE);

        }
    });

1 个答案:

答案 0 :(得分:1)

尝试在列表项模型类中添加一个布尔标志,默认值为false:

private boolean isSlideVisible;

public boolean isSlideVisible() {
   return isSlideVisible;
}

public void setSlideVisible(boolean isSlideVisible) {
    this.isSlideVisible = isSlideVisible;
}

现在更改特定项目的标志副词的状态并通知适配器:

fulfilledView.details.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      if(values.get(position).isSlideVisible()){
         values.get(position).setSlideVisible(false);
      }else{
         values.get(position).setSlideVisible(true);      
      }
      notifyDataSetChanged ()
    }
 });

根据标志值显示幻灯片视图:

if(values.get(position).isSlideVisible()){
   fulfilledView.slide.setVisibility(View.VISIBLE);
}else{
   fulfilledView.slide.setVisibility(View.GONE);
}