I am working on a client-server project in android.I need to parse xml from 
url and place it in Expandablelistview. The problem arises when i am trying 
to place childs inside each group based on the data coming from server. My 
code only places the first child inside first group, but i can't create two 
separate groups.

I need to place "payment_method" and "total" inside respective 
group(e.g:Groupname:OrderInfo,customerInfo, 
Childname(OrderInfo):payment_method,total, 
Childname(CustomerInfo):firstname,lastname).My code can placed 
Childname(OrderInfo) inside OrderInfo group, but i wish to need when i 
click customerInfo group, the firstname,lastname also displayed 
customerInfo group.pleasehelp me how is to do. my code is attached 
above.please give me some solution for develop this.

Thank You.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
package com.example.androidhive;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import android.app.ExpandableListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.SimpleExpandableListAdapter;
import android.widget.TextView;
 
public class SingleMenuItemActivity extends ExpandableListActivity {
	
	
	
	
	static final String KEY_ARTIST = "payment_method";
	static final String KEY_ARTIST = "firstname";
	
	static final String KEY_DURATION = "lastname";
	static final String KEY_DURATION = "total";
	static final String OrderInfo = "OrderInfo";
	static final String CustomerInfo = "CustomerInfo";
    @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[] { "OrderInfo"},  // 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"},  
                   new int[] { R.id.name_label,R.id.cost_label}// 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());
        }
    }
    
    
    /* Creating the Hashmap for the row */
    @SuppressWarnings("unchecked")
    private List createGroupList() {
          ArrayList result = new ArrayList();
          for( int i = 0 ; i < 1 ; ++i ) { // 15 groups........
            HashMap m = new HashMap();
           // HashMap<String,String> map = new HashMap<String,String>();
           // m.put( "CustomerInfo","CustomerInfo"); // the key and it's value.
            m.put( "OrderInfo", OrderInfo);
          
            result.add( m);
          }
          return (List)result;
          
    }
    
 

    /* 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());
        }
    }
}

Reply via email to