2

我开发了一个ExpandableListView.

我的代码是:

public class SingleMenuItemActivity extends ExpandableListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.particular);

    // Construct Expandable List
final String LABEL = "label";
final String VALUE = "value";
final String GROUP1 = "Group1";
final String GROUP2 = "Group1";
    final LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final ArrayList<HashMap<String, String>> headerData = new ArrayList<HashMap<String, String>>();

    final HashMap<String, String> group1 = new HashMap<String, String>();
    group1.put(GROUP1, "OrderInformation");
    headerData.add( group1 );

    final HashMap<String, String> group2 = new HashMap<String, String>();
    group2.put(GROUP2, "CustomerInformation");
    headerData.add( group2);
    final ArrayList<ArrayList<HashMap<String, Object>>> childData = new ArrayList<ArrayList<HashMap<String, Object>>>();

    final ArrayList<HashMap<String, Object>> group1data = new ArrayList<HashMap<String, Object>>();
    childData.add(group1data);

    final ArrayList<HashMap<String, Object>> group2data = new ArrayList<HashMap<String, Object>>();
    childData.add(group2data);

    // Set up some sample data in both groups
    for( int i=0; i<1; ++i) {
        final HashMap<String, Object> map = new HashMap<String,Object>();
        String s= getIntent().getStringExtra("payment_method");
        String s1= getIntent().getStringExtra("subtotal");
      map.put(LABEL, "Payment Method:");
        map.put(VALUE, s);
       group1data.add(map);
      final HashMap<String, Object> map1 = new HashMap<String, Object>();
    map1.put(LABEL, "Subtotal:");
    map1.put(VALUE, s1);
    group1data.add(map1);
      }
    final HashMap<String, Object> map = new HashMap<String, Object>();
    String s3= getIntent().getStringExtra("firstname");
    String s4= getIntent().getStringExtra("lastname");
    String s1= getIntent().getStringExtra("phone");
    String s2= getIntent().getStringExtra("url");
    map.put(LABEL, "Firstname::");
    map.put(VALUE, s3);
    group2data.add(map);


    // Create new map for second row
    // You should use loop to do this
    // insert new values and add to group row
    final HashMap<String, Object> map1 = new HashMap<String, Object>();
    map1.put(LABEL, "Lastname:");
    map1.put(VALUE, s4);
          group2data.add(map1);
        final HashMap<String, Object> map2 = new HashMap<String, Object>();
    map2.put(LABEL, "URL:");
    map2.put(VALUE, s1);
    group2data.add(map2);
    final HashMap<String, Object> map3 = new HashMap<String, Object>();
    map3.put(LABEL, "Phone:");
    map3.put(VALUE, s2);
    group2data.add(map3);
     setListAdapter(new SimpleExpandableListAdapter(this, headerData,
            R.layout.group_row, new String[] { GROUP1, GROUP2 }, // the names
                                                                // of the
                                                                // data
            new int[] { R.id.order }, // the text field to populate with the
                                        // field data
            childData, 0, null, new int[] {}) {
        @Override
        public View getChildView(int groupPosition, int childPosition,
                boolean isLastChild, View convertView, ViewGroup parent) {
            final View v = super.getChildView(groupPosition, childPosition,
                    isLastChild, convertView, parent);



            // Populate your custom view here
            ((TextView) v.findViewById(R.id.label))
            .setText((String) ((Map<String, Object>) getChild(
                    groupPosition, childPosition)).get(LABEL));

            ((TextView) v.findViewById(R.id.value))
                    .setText((String) ((Map<String, Object>) getChild(
                            groupPosition, childPosition)).get(VALUE));

            return v;
        }

        @Override
        public View newChildView(boolean isLastChild, ViewGroup parent) {

            return layoutInflater.inflate(
                    R.layout.expandable_list_item_with_image, null, false);

        }
    });
    ExpandableListView list = (ExpandableListView) findViewById(android.R.id.list);
    list.setOnChildClickListener(new OnChildClickListener() {
        public boolean onChildClick(ExpandableListView parent, View v,
                int groupPosition, int childPosition, long id) {
            System.out.println("Group:" + groupPosition + ", Child: "
                    + childPosition);
            return true;
        }
    });

}

     }

这里这种格式是我当前的 o/p:

 -->Orderinformation
          * payment_method
          * subtotal
--->Customerinformation

           *firstname
           *lastname
           *phone
           *url

但我希望需要的格式是:

-->Orderinformation
          * payment_method
          * subtotal
--->Customerinformation
        -->personalinformation
                *firstname
                *lastname
        -->Contactinformation
                *phone
                *url

如何在HashMap此处使用并ExpandableListView在另一个中创建ExpandableListView. 请给我一些解决方案。

4

0 回答 0