0

拡張可能なカスタムアダプターにチェックボックスと子要素を持つカスタムアダプターがあり、親アイテムが選択されている場合-私の場合、注文が選択/チェックされている場合、注文はチェックボックスなしで新しいカスタムアダプターに渡されます。親、つまりオーダーを渡すことはできますが、子要素、つまりオーダーの子であるアイテムを渡すことができません。したがって、選択した注文の子要素を新しいアダプター ビューに渡す必要があります。 ここに画像の説明を入力

ここに画像の説明を入力

私のコード:

      try {     
            System.out.println("READ/PARSING JSON");                            
            serverStatus = jobj.getString("SERVER_STATUS"); 
                System.out.println("serverStatusObj:  "+serverStatus);                          
                JSONArray serverResponseArray2=jobj.getJSONArray("SERVER_RESPONSE");    
                for (int m = 0; m < serverResponseArray2.length(); m++) {
                     String SERVER_RESPONSE = serverResponseArray2.getString(m);                 
                     JSONObject Open_Orders_obj = new JSONObject(SERVER_RESPONSE);
                     mMAX_ORDERS_TOBEPICKED = Open_Orders_obj.getInt("MAX_ORDERS_TOBEPICKED");  
                     JSONArray ja = Open_Orders_obj.getJSONArray("ORDER_ITEM_DETAILS");     
                     order_Item_Values.clear(); 
                     mOpenOrders = new ArrayList<OpenOrders>(ja.length());                  
                        for(int i=0; i<ja.length(); i++){
                           String ORDER_ITEM_DETAILS = ja.getString(i);                            
                           jobj1 = new JSONObject(ORDER_ITEM_DETAILS);
                           String ORDERNAME = jobj1.getString("ORDERNAME");     
                           String ORDERID = jobj1.getString("ORDERID");    
                           final OpenOrders parent = new OpenOrders();
                           parent.setOrderName(ORDERNAME+ " "+  i);
                           parent.setOrderID(ORDERID);
                           parent.setChecked((i % 2) == 0);                      
                          OpenOrders    openOrderObj= new OpenOrders(ORDERID,ORDERNAME);                                
                           JSONArray Order_Items = jobj1.getJSONArray("ITEMS"); 
                            itemList =new ArrayList<String>();                            
                            parent.setChildren(new ArrayList<Child>());
                            for(int k=0; k<Order_Items.length(); k++){
                                String ITEMS = Order_Items.getString(k);
                                System.out.println(ITEMS);
                                ItemObj = new JSONObject(ITEMS);
                                String ITEMNUMBER = ItemObj.getString("ITEMNUMBER");    
                                String ITEMNAME = ItemObj.getString("ITEMNAME");    
                                itemList.add(ITEMNAME);//This adds item  name's  to the  ArrayList named 'itemList'
                                openOrderObj.setItemID(ITEMNUMBER);
                                openOrderObj.setItemName(ITEMNAME);
                                System.out.println("item name"+ITEMNAME);                           
                            final Child child = new Child();
                            child.setName(ITEMNAME  + i + "/" + k);
                            parent.getChildren().add(child);                                  
                            }
                            mOpenOrders.add(parent);
                        }                 
                   }

        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }  //***End code to read  json content from text file saved in device   
enter code here

私の開いている注文クラス:

    import java.io.Serializable;
    import java.util.ArrayList;

    import com.kits.ddf_order_model.Child;

        public class OpenOrders implements Serializable {
            /**
             * 
             */
            private static final long serialVersionUID = 1L;
            private String orderID;
            private String orderName;    

            private boolean selected;

            private boolean checked;
            private ArrayList<Child> children;

            private String itemID;
            private String  itemName;

            public OpenOrders(String orderID, String orderName) {
                super();
                this.orderID = orderID;
                this.orderName = orderName;
            }
            public OpenOrders() {
                // TODO Auto-generated constructor stub
            }
            public String getOrderID() {
                return orderID;
            }
            public void setOrderID(String orderID) {
                this.orderID = orderID;
            }
            public String getOrderName() {
                return orderName;
            }
            public void setOrderName(String orderName) {
                this.orderName = orderName;
            }
             @Override
             public String toString() {          
                 return  this.orderName;
             }



             public boolean isSelected() {
              return selected;
             }

              public void setSelected(boolean selected) {
              this.selected = selected;
             }

                public ArrayList<Child> getChildren()
                {
                    return children;
                }

                public void setChildren(ArrayList<Child> children)
                {
                    this.children = children;
                }
                public boolean isChecked() {
                    return checked;
                }
                public void setChecked(boolean checked) {
                    this.checked = checked;
                }
                public String getItemID() {
                    return itemID;
                }
                public void setItemID(String itemID) {
                    this.itemID = itemID;
                }
                public String getItemName() {
                    return itemName;
                }
                public void setItemName(String itemName) {
                    this.itemName = itemName;
                }
        }

私の子クラス:

    public class Child
    {
private String name;

public String getName()
{
    return name;
}

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

ボタンがクリックされたとき、私がすることは次のとおりです。

                               button.setOnClickListener(new OnClickListener() {            
                                @Override
                                public void onClick(View v) {
                                    // TODO Auto-generated method stub
                                      if(mAdapter != null) {              
                                          int isSelectedOrderNumber=0;//This   Variable will check with the parameter  passed from server
                                          mOpenOrdersSelected = new ArrayList<OpenOrders>();              
                                          StringBuffer sb = new StringBuffer();
                                          Iterator<OpenOrders> it = mOpenOrders.iterator();
                                          while(it.hasNext())
                                          {
                                              OpenOrders objOpenOrders = it.next();
                                              //Do something with objOpenOrders
                                              if (objOpenOrders.isChecked()) {
                                                  isSelectedOrderNumber++;
                                                 // mOpenOrdersSelected.add(new OpenOrders(objOpenOrders.getOrderID(),objOpenOrders.getOrderName()));
                                                  sb.append(objOpenOrders.getOrderID());
                                                  sb.append(",");
                                                  final OpenOrders parent = new OpenOrders(objOpenOrders.getOrderID(),objOpenOrders.getOrderName());
                                                  ArrayList<Child>  mOpenOrderItems=objOpenOrders.getChildren();
                                                  Iterator<Child> i = mOpenOrderItems.iterator();
                                                mOpenOrdersSelected.add(parent);
                                                }
                                              }

                                          //Below Condition Will Check the selected Items With parameter passed "mMAX_ORDERS_TOBEPICKED"
                                             if(isSelectedOrderNumber<1){
                                                ShowErrorDialog("Please Select atleast One order");
                                                return;
                                              }
                                            if(isSelectedOrderNumber>mMAX_ORDERS_TOBEPICKED){
                                                ShowErrorDialog(" Select Maximum of  "+mMAX_ORDERS_TOBEPICKED+ " Orders only to process");
                                                return;
                                              }
                                     //Below code is to Call again the adapter and Displays the Order's which are checked/selected.                                            
                                        expListView = (ExpandableListView) findViewById(R.id.expandable_order_item_list);                                       
                                        ExpandableOrderSelectedListAdapter mOrderSelectedAdapter = new ExpandableOrderSelectedListAdapter(SelectLocationActivity.this,mOpenOrdersSelected);
                                        expListView.setAdapter(mOrderSelectedAdapter);                         
                                        expListView.setOnItemClickListener(new OnItemClickListener() {
                                                @Override
                                                public void onItemClick(AdapterView<?> parent, View view,
                                                        int position, long id) {
                                                    //nothing to do , as  Null Pointer exception Occurred ,to avoid that I just used this "setOnItemClickListener"
                                                }
                                                });

                                         button.setVisibility(View.GONE);//Hide  the  Initial Button in the view

                                         fullfilment_btn.setVisibility(View.VISIBLE);//Displays the confirm Button
                                         fullfilment_btn.setOnClickListener(new OnClickListener() {             
                                            @Override
                                            public void onClick(View arg0) {
                                                // TODO Auto-generated method stub

                                              }
                                            });
                                      }
                                }
                            });

したがって、コードのこの部分では、子要素の反復中にエラーが発生します。

どんな助けでも素晴らしいでしょう

4

1 に答える 1

0

この問題を for ループで解決しました。これにより、子が新しい「mOpenOrderSelected」変数に追加されます。

  if (objOpenOrders.isChecked()) {
                                              isSelectedOrderNumber++;
                                              sb.append(objOpenOrders.getOrderID());
                                              sb.append(",");
                                              final OpenOrders parent = new OpenOrders(objOpenOrders.getOrderID(),objOpenOrders.getOrderName());
                                              ArrayList<Child>  mOpenOrderItems=objOpenOrders.getChildren();                                                     
                                            parent.setChildren(new ArrayList<Child>());
                                            for(int k=0; k<mOpenOrderItems.size(); k++){                                                      
                                               final Child child = (Child) mOpenOrderItems.get(k);
                                               Log.d("ChildItemsname", "ChildItemsname:"+child.getName());
                                               parent.getChildren().add(child);  
                                              }
                                            mOpenOrdersSelected.add(parent);
                                            }

したがって、新しいボタン クリック コードは次のようになります。

         button.setOnClickListener(new OnClickListener() {          
                                @Override
                                public void onClick(View v) {
                                    // TODO Auto-generated method stub
                                      if(mAdapter != null) {              
                                          int isSelectedOrderNumber=0;//This   Variable will check with the parameter  passed from server
                                          mOpenOrdersSelected = new ArrayList<OpenOrders>();              
                                          StringBuffer sb = new StringBuffer();
                                          Iterator<OpenOrders> it = mOpenOrders.iterator();
                                          while(it.hasNext())
                                          {
                                              OpenOrders objOpenOrders = it.next();
                                              //Do something with objOpenOrders
                                              if (objOpenOrders.isChecked()) {
                                                  isSelectedOrderNumber++;
                                                  sb.append(objOpenOrders.getOrderID());
                                                  sb.append(",");
                                                  final OpenOrders parent = new OpenOrders(objOpenOrders.getOrderID(),objOpenOrders.getOrderName());
                                                  ArrayList<Child>  mOpenOrderItems=objOpenOrders.getChildren();                                                     
                                                parent.setChildren(new ArrayList<Child>());
                                                for(int k=0; k<mOpenOrderItems.size(); k++){                                                      
                                                   final Child child = (Child) mOpenOrderItems.get(k);
                                                   Log.d("ChildItemsname", "ChildItemsname:"+child.getName());
                                                   parent.getChildren().add(child);  
                                                  }
                                                mOpenOrdersSelected.add(parent);
                                                }
                                              }

                                          //Below Condition Will Check the selected Items With parameter passed "mMAX_ORDERS_TOBEPICKED"
                                             if(isSelectedOrderNumber<1){
                                                ShowErrorDialog("Please Select atleast One order");
                                                return;
                                              }
                                            if(isSelectedOrderNumber>mMAX_ORDERS_TOBEPICKED){
                                                ShowErrorDialog(" Select Maximum of  "+mMAX_ORDERS_TOBEPICKED+ " Orders only to process");
                                                return;
                                              }
                                     //Below code is to Call again the adapter and Displays the Order's which are checked/selected.                                            
                                        expListView = (ExpandableListView) findViewById(R.id.expandable_order_item_list);                                       
                                        ExpandableOrderSelectedListAdapter mOrderSelectedAdapter = new ExpandableOrderSelectedListAdapter(SelectLocationActivity.this,mOpenOrdersSelected);
                                        expListView.setAdapter(mOrderSelectedAdapter);                         
                                        expListView.setOnItemClickListener(new OnItemClickListener() {
                                                @Override
                                                public void onItemClick(AdapterView<?> parent, View view,
                                                        int position, long id) {
                                                    //nothing to do , as  Null Pointer exception Occurred ,to avoid that I just used this "setOnItemClickListener"
                                                }
                                                });

                                         button.setVisibility(View.GONE);//Hide  the  Initial Button in the view
                                         fullfilment_btn.setVisibility(View.VISIBLE);//Displays the confirm Button
                                         fullfilment_btn.setOnClickListener(new OnClickListener() {             
                                            @Override
                                            public void onClick(View arg0) {
                                                // TODO Auto-generated method stub

                                              }
                                            });
                                      }
                                }
                            });
于 2013-09-17T10:17:19.547 に答える