如何从一个适配器调用方法到当前适配器活动

时间:2016-11-04 06:05:22

标签: android

是否可以从一个适配器活动调用方法到另一个适配器活动?

当我在列表视图中按项目时,我有列表视图通过选中复选框并按确定,我将获得带复选框的弹出窗口。我必须禁用主列表中的项目,但该项目在弹出窗口列表中禁用主列表加载到另一个适配器,所以我认为通过禁用项目并附加到复选框它可能工作。所以请帮助我。

主要活动:

listView1.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

                 @Override
                 public boolean onItemLongClick(AdapterView<?> parent, View view,
                 int position, long id) {
                 // TODO Auto-generated method stub
                     newListitems2.clear();
                  newListitems2.addAll(itemsList1);

                    // ArrayList newListitems2 = new ArrayList();
                     //newListitems2.add(itemsList1);
                     dialog = new Dialog(PendingOrdersActitvity.this);
                        dialog.setContentView(R.layout.itembumping);
                        dialog.show();


                        list1=(ListView )dialog.findViewById(R.id.list1);

                        ItemBumpingAdapter adapter2 = new ItemBumpingAdapter(PendingOrdersActitvity.this,newListitems2);
                        list1.setAdapter(adapter2);

                        Button okButton = (Button)dialog.findViewById(R.id.ok1);
                        okButton.setOnClickListener(new OnClickListener() {

                            @Override
                            public void onClick(View v) {

                                dialog.dismiss();

                            }
                 });
                            Button cancelButton = (Button)dialog.findViewById(R.id.Cancel1);
                    cancelButton.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            dialog.dismiss();
                        }



                        });
                        return true;

                 }
                            });

这是我点击项目对话框的主要活动。

对话框适配器:

 public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub


                        ViewHolder holder;
                        String item = null, qty = null;
                        if (convertView == null) {
                            holder = new ViewHolder();
                            convertView = inflator.inflate(R.layout.itembumpingadapter, null);
                            holder.qty = (TextView) convertView.findViewById(R.id.qty);
                            holder.name = (TextView) convertView.findViewById(R.id.item);
                            holder.childText = (TextView) convertView
                                    .findViewById(R.id.childitem);
                            holder.qtyChild = (TextView) convertView
                                    .findViewById(R.id.qtychild);
                             holder.checkbox = (CheckBox) convertView.findViewById(R.id.chckbox1);
                            convertView.setTag(holder);

                        } else {

                            holder = (ViewHolder) convertView.getTag();
                        }
                        parentobjid=newListitems.get(position).getParentobjectid();
                        if(!parentobjid.isEmpty())
                        {
                            holder.name.setText("   " +newListitems.get(position).getItemnNameDisplay());
                            holder.name.setTextColor(Color.parseColor("#CC0000"));
                            holder.qty.setText("      "+String.valueOf(newListitems.get(position)
                                    .getQuantityDisplay()));
                            holder.qty.setTextColor(Color.parseColor("#CC0000"));
                        }
                        else
                        {

                        holder.name.setText(newListitems.get(position).getItemnNameDisplay());
                        holder.qty.setText(String.valueOf(newListitems.get(position)
                                .getQuantityDisplay()));
                        holder.name.setTextColor(Color.parseColor("#FFFFFF"));
                        holder.qty.setTextColor(Color.parseColor("#FFFFFF"));
                        holder.checkbox.setChecked(false);

                        holder.checkbox.setTag(position);
                        holder.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
                            public void onCheckedChanged(CompoundButton buttonView,
                                    boolean isChecked) {


                                int position=(Integer)buttonView.getTag();


                                  newListitems.get(position).setChecked(!newListitems.get(position).isChecked());


                            }
                        });
                        if(newListitems.get(position).isChecked()){
                            holder.name.setEnabled(false);
                            holder.name.setBackgroundColor(Color.parseColor("#DCDBDB"));

                            }else{
                            holder.name.setEnabled(true);
                            }

这是一个适配器,其中加载了列表和复选框。

列表适配器:

 public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub


                        ViewHolder holder;
                        String item = null, qty = null;
                        if (convertView == null) {
                            holder = new ViewHolder();
                            convertView = inflator.inflate(R.layout.itembumpingadapter, null);
                            holder.qty = (TextView) convertView.findViewById(R.id.qty);
                            holder.name = (TextView) convertView.findViewById(R.id.item);
                            holder.childText = (TextView) convertView
                                    .findViewById(R.id.childitem);
                            holder.qtyChild = (TextView) convertView
                                    .findViewById(R.id.qtychild);
                             holder.checkbox = (CheckBox) convertView.findViewById(R.id.chckbox1);
                            convertView.setTag(holder);

                        } else {

                            holder = (ViewHolder) convertView.getTag();
                        }
                        parentobjid=newListitems.get(position).getParentobjectid();
                        if(!parentobjid.isEmpty())
                        {
                            holder.name.setText("   " +newListitems.get(position).getItemnNameDisplay());
                            holder.name.setTextColor(Color.parseColor("#CC0000"));
                            holder.qty.setText("      "+String.valueOf(newListitems.get(position)
                                    .getQuantityDisplay()));
                            holder.qty.setTextColor(Color.parseColor("#CC0000"));
                        }
                        else
                        {

                        holder.name.setText(newListitems.get(position).getItemnNameDisplay());
                        holder.qty.setText(String.valueOf(newListitems.get(position)
                                .getQuantityDisplay()));
                        holder.name.setTextColor(Color.parseColor("#FFFFFF"));
                        holder.qty.setTextColor(Color.parseColor("#FFFFFF"));

这是我的适配器,其中加载了主列表。如果我选中复选框并按确定我要禁用或更改主列表中项目的颜色,但它在对话框列表中更改。

请帮帮我

0 个答案:

没有答案