1

私はアンドロイドでクライアントサーバープロジェクトに取り組んでいます。URLからxmlを解析してExpandablelistviewに配置する必要があります。サーバーからのデータに基づいて各グループ内に子を配置しようとすると、問題が発生します。私のコードは、最初の子の値のみを最初のグループ内に配置し、2 番目の子の値は 2 番目のグループに配置します。

最初のグループ内に「payment_method」と「total」を配置する必要があり、firstname と lastname は 2 番目のグループに配置する必要があります (例:Groupname:OrderInfo,customerInfo, Childname(OrderInfo):payment_method,total, Childname(CustomerInfo):firstname,lastname) )私のコードはChildname(OrderInfo)をOrderInfoグループ内に配置できますが、customerInfoグループをクリックすると、firstname、lastnameも表示されますcustomerInfoグループが必要です。どうすればよいか教えてください。これは私のコードです:

public class SingleMenuItemActivity extends ExpandableListActivity {




static final String KEY_ARTIST = "payment_method";
static final String KEY_FNAME = "firstname";
    static final String KEY_LNAME = "lastname";
static final String KEY_DURATION = "total";
static final String OrderInfo = "OrderInfo";
static final String CustomerInfo = "CustomerInfo";
    private static final String GroupID = "GroupID";
@SuppressWarnings("unchecked")
public void onCreate(Bundle savedInstanceState) {
    try{
         super.onCreate(savedInstanceState);
         setContentView(R.layout.particular);

    SimpleExpandableListAdapter expListAdapter =
        new SimpleExpandableListAdapter(
                this,

                createGroupList(),              // Creating group List.
                R.layout.group_row, 

              // Group item layout XML.
                new String[] { "GroupID"},  // the key of group item.e
                new int[] { R.id.order},

                // ID of each group item.-Data under the key goes into this TextView.
                createChildList(),              // childData describes second-level entries.
                R.layout.single_list_item,  
              //  new String[] {"KEY_ARTIST"},  
               // new int[] { R.id.payment_label}  // Keys in childData maps to display.
                  // Layout for sub-level entries(second level).
               new String[] {"KEY_ARTIST","KEY_DURATION","KEY_FNAME","KEY_LNAME"},  
               new int[] { R.id.name_label,R.id.cost_label,R.id.firstname,R.id.lastname}// Keys in childData maps to display.
             //   new int[] { R.id.payment_label,R.id.total_label}     // Data under the keys above go into these TextViews.
            );
        setListAdapter( expListAdapter );       // setting the adapter in the list.

    }catch(Exception e){
        System.out.println("Errrr +++ " + e.getMessage());
    }
}


 private List createGroupList() {

    Log.d(TAG, "Adding groups values");
    List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
    HashMap<String, String> statusMap = new HashMap<String, String>();
    statusMap.put(GroupID, "OrderInfo");
    list.add(statusMap);
    HashMap<String, String> usersMap = new HashMap<String, String>();
    usersMap.put(GroupID, "CustomerInfo");
    list.add(usersMap);
    Log.d(TAG, "Adding groups values successfull");
    return list;
   }



/* creatin the HashMap for the children */
@SuppressWarnings("unchecked")
private List createChildList() {

    ArrayList result = new ArrayList();
    for( int i = 0 ; i < 1 ; ++i ) { // this -15 is the number of groups(Here it's fifteen)
      /* each group need each HashMap-Here for each group we have 3 subgroups */
      ArrayList secList = new ArrayList();
      for( int n = 0 ; n < 1 ; n++ ) {
        HashMap child = new HashMap();




       String s= getIntent().getStringExtra("payment_method");
       String s1= getIntent().getStringExtra("total");


     child.put( "KEY_ARTIST", s);
     child.put( "KEY_DURATION", s1);

        secList.add( child);
      }
     result.add( secList );
    }
    return result;
}
public void  onContentChanged  () {
    System.out.println("onContentChanged");
    super.onContentChanged();
}
/* This function is called on each child click */
public boolean onChildClick( ExpandableListView parent, View v, int groupPosition,int childPosition,long id) {
    System.out.println("Inside onChildClick at groupPosition = " + groupPosition +" Child clicked at position " + childPosition);
    return true;
}

/* This function is called on expansion of the group */
public void  onGroupExpand  (int groupPosition) {
    try{
         System.out.println("Group exapanding Listener => groupPosition = " + groupPosition);
    }catch(Exception e){
        System.out.println(" groupPosition Errrr +++ " + e.getMessage());
    }
}
 }

私の疑問は、最初の子の値を最初のグループ内に配置し、2 番目の子の値を 2 番目のグループに配置する方法です。 2 番目のグループ。2 番目のグループをクリックする必要がある場合は、強制的に閉じられていることを意味します。助けてください。どうすればよいですか。

4

0 に答える 0