将值从一个适配器更新到android中的另一个可扩展列表视图

时间:2016-07-27 05:34:46

标签: android expandablelistview

我从检查页面适配器获得价值。如果在一个列表项中单击加号图像,计数值会增加。我想在expandablelistview适配器中更新子项的特定值。如何从检查中更新该特定子值页面适配器。

Checkinapadater:

 @Override
        public void onBindViewHolder(final MyViewHolder holder, final int position) {



            final Movie1 m = movieItems.get(position);


               if (m.getfood_totalprice() != null) {
                if (!m.getfood_totalprice().equals("null")) {
                    holder.amount.setText(m.getfood_totalprice());
                }
            }
            if (m.getfood_count() != null) {
                if (!m.getfood_count().equals("null")) {
                    holder.item_count.setText(m.getfood_count());
                }

            }


            holder.plus.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    int i = Integer.parseInt(holder.item_count.getText().toString());
                    if(i>=0){
                    int count = i + 1;

                    holder.item_count.setText(Integer.toString(count));

                    value = Integer.toString(count);

                }
            });

            holder.minus.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    int i = Integer.parseInt(holder.item_count.getText().toString());
                    if(i>0){

                    int count = i - 1;
                    holder.item_count.setText(Integer.toString(count));

                }
                   });

        }

Exapanadablelistapater:

 @Override
    public View getChildView(final int groupPosition, final int childPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {

        final Child child = (Child) getChild(groupPosition, childPosition);
        final Child modelChild = groups.get(groupPosition).getItems().get(childPosition);
        if (convertView == null) {
            LayoutInflater inflator = LayoutInflater.from(parent.getContext());
            convertView = inflator.inflate(R.layout.detail_list, null);
            viewHolder = new ViewHolder();

            viewHolder.minus = (ImageView) convertView.findViewById(R.id.minus);
            viewHolder.plus = (ImageView) convertView.findViewById(R.id.plus);
            viewHolder.green = (ImageView) convertView.findViewById(R.id.green);
            viewHolder.red = (ImageView) convertView.findViewById(R.id.red);
            viewHolder.item_count = (TextView) convertView.findViewById(R.id.count);
       //viewHolder.txtView  = (TextView) ((AppCompatActivity)context).findViewById(R.id.checked_item);

            convertView.setTag(viewHolder);
        }
        else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tv.setText(child.getName());
        viewHolder.amount.setText(child.getPrice());


        viewHolder.item_count.setText(Integer.toString(child.getCount()));


        viewHolder.plus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


                    if(modelChild.getCount()>=0)  // set your count default 0 when you bind data initially
                    {


                        int count = (modelChild.getCount()) + 1;
                        modelChild.setCount(count);

                        int s= Integer.parseInt(Detailpage.item.getText().toString());

                        itemname.setText(Integer.toString(count1));
                        // viewHolder.txtView.setText(Integer.toString(count1)+"items");
                        count1=s+1;
                        Detailpage.item.setText(Integer.toString(count1));
                        int foodprice=0;
                        foodprice=Integer.parseInt(child.getPrice());

                        total1=child.getPrice();
                        value=Integer.toString(modelChild.getcount());
//
                        name = modelChild.getName();

                        id=child.getId();


                        new AsyncT().execute(user_id,res_id,id,name,total1,value);

                        groups.get(groupPosition).getItems().set(childPosition, modelChild);
                        notifyDataSetChanged();
                    }

            }});


        viewHolder.minus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


                    if(modelChild.getCount()>0)  // set your count default 0 when you bind data initially
                    {   int count = modelChild.getCount() - 1;
                        modelChild.setCount(count);
                        int s= Integer.parseInt(Detailpage.item.getText().toString());
                        count1=s-1;
                        Detailpage.item.setText(Integer.toString(count1));

                         name=modelChild.getName();
//        

                        int foodprice=0;
                        foodprice=Integer.parseInt(child.getPrice());

                        int total = foodprice * child.getcount();
                        total1=child.getPrice();
//                         total1=Integer.toString(total);
                         value=Integer.toString(count);
                         id=child.getId();
                        if(count>0) {
                            new AsyncT().execute(user_id, res_id, id, name, total1, value);
                        }


                    }

                    modelChild.setChildName(modelChild.getChildName());
                    // set your other items if any like above
                    groups.get(groupPosition).getItems().set(childPosition, modelChild);
                    notifyDataSetChanged();

            }
        });





        return convertView;
    }

Movie1模型(签入页面):`

公共类Movie1 {

public  String food_id,food_count,food_item,food_price,food_resid,food_totalprice;



public void setfood_id(String food_id) {
    this.food_id = food_id;
}

public void setfood_count(String food_count) {
    this.food_count = food_count;
}

public void setfood_price(String food_price) {
    this.food_price = food_price;
}

public void setfood_item(String food_item) {
    this.food_item = food_item;
}

public String getfood_item() {
    return food_item;
}

public String getfood_count() {
    return food_count;
}

public String getfood_price() {
    return food_price;
}

public void setfood_resid(String food_resid) {
    this.food_resid = food_resid;
}

public String getfood_resid() {
    return food_resid;
}

public String getfood_id() {
    return food_id;
}

public void setfood_totalprice(String food_totalprice) {
    this.food_totalprice = food_totalprice;
}

public String getfood_totalprice() {
    return food_totalprice;
}

}

` 子模型:(可扩展列表视图)

 public class Child {

    private String Name,childName,item_status,image1,available_from,available_to,price,id,status;
    private int Image,count;
    public Object getstatus;



    public String getName() {
        return Name;
    }

    public void setName(String Name) {
        this.Name = Name;
    }

    public int getImage() {
        return Image;
    }

    public void setImage(int Image) {
        this.Image = Image;
    }

    public void setcount(int count) {
        this.count = count;
    }

    public int getcount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public String getChildName() {
        return childName;
    }

    public int getCount() {
        return count;
    }

    public void setChildName(String childName) {
        this.childName = childName;
    }

    public void setItem_status(String item_status) {
        this.item_status = item_status;
    }

    public void setImage1(String image1) {
        this.image1 = image1;
    }

    public void setAvailable_to(String available_to) {
        this.available_to = available_to;
    }

    public void setAvailable_from(String available_from) {
        this.available_from = available_from;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPrice() {
        return price;
    }

    public String getImage1() {
        return image1;
    }

    public String getItem_status() {
        return item_status;
    }

    public String getId() {
        return id;
    }

    public void setstatus(String status) {
        this.status = status;
    }
    public String getstatus() {
        return status;
    }



}

`checkin

Expandablelist adapter

0 个答案:

没有答案