-1

私は1つの動的expandablelistviewを正常に開発しました...別のexpandalilistview内でexpandablelictviewを動的に作成する方法. これは私のコードです:

public class SingleMenuItemActivity extends ExpandableListActivity {
Button btninsert;   
String selectedItem;

static final String KEY_NAME = "orderid"; 
static final String KEY_STATUS = "status"; 
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.particular);
Button btninsert = (Button) findViewById(R.id.btn_insert);
btninsert.setOnClickListener(new View.OnClickListener() {


public void onClick(View v) {
     String s= getIntent().getStringExtra("orderid");
     String s1= getIntent().getStringExtra("status");
Intent i = new Intent(getApplicationContext(), InsertionExample.class);
i.putExtra(KEY_NAME, s);
i.putExtra(KEY_STATUS, s1);
startActivity(i);
}
});


    // Construct Expandable List
    final String NAME1 = "payment_method1";
    final String NAME = "payment_method";
    final String TOTAL = "total";
    final String TOTAL1 = "total1";

    final String IMAGE = "image"; 
    final String FNAME1 = "firstname1";

    final String FNAME = "firstname";
    final String LNAME1 = "lastname1";
    final String LNAME = "lastname";
    final String PHONE1 = "phone1";

    final String PHONE = "phone";
    final String EMAIL1 = "email1";
    final String EMAIL = "email";
    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(NAME, "OrderInfo");
    headerData.add( group1 );

    final HashMap<String, String> group2 = new HashMap<String, String>();
    group2.put(NAME, "CustomerInfo");
    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, String>> group2data = new ArrayList<HashMap<String,String>>();
    final HashMap<String, String> group3 = new HashMap<String, String>();
    group3.put(NAME, "PersonalInfo");
    group2data.add( group3 );

    final HashMap<String, String> group4 = new HashMap<String, String>();
    group4.put(NAME, "ContactInfo");
    group2data.add( group4 );
    final ArrayList<HashMap<String, Object>> group3data = new ArrayList<HashMap<String, Object>>();
    childData.add(group3data);
    final ArrayList<HashMap<String, Object>> group4data = new ArrayList<HashMap<String, Object>>();
    childData.add(group4data);

    // Set up some sample data in both groups

        final HashMap<String, Object> map = new HashMap<String,Object>();
        String s= getIntent().getStringExtra("payment_method");
        String s1= getIntent().getStringExtra("total");

        map.put(NAME1, "Payment_method:");
        map.put(NAME, s );
        map.put(TOTAL1, "Total:");
        map.put(TOTAL, s1);

        group1data.add(map);
     //  map.put(IMAGE, getResources().getDrawable((i%3==0? R.drawable.color_green : R.drawable.color_red)));
      //  ( i%2==0 ? group1data : group2data ).add(map);


    final HashMap<String, Object> map1 = new HashMap<String,Object>();
    String s2= getIntent().getStringExtra("firstname");
    String s3= getIntent().getStringExtra("lastname");

    map1.put(FNAME, s2);
    map1.put(FNAME1, "Firstname:");
    map1.put(LNAME, s3);
    map1.put(LNAME1, "Lastname:");

 //  map.put(IMAGE, getResources().getDrawable(R.drawable.color_yellow));

    group3data.add(map1);

    final HashMap<String, Object> map2 = new HashMap<String,Object>();
    String s4= getIntent().getStringExtra("phone");
    String s5= getIntent().getStringExtra("email");

    map2.put(PHONE, s4);
    map2.put(PHONE1, "Phone:");
    map2.put(EMAIL, s5);
    map2.put(EMAIL1, "Email:");

 //  map.put(IMAGE, getResources().getDrawable(R.drawable.color_yellow));
    group4data.add(map2);

    setListAdapter( new SimpleExpandableListAdapter(
            this,
            headerData,
            R.layout.group_row,
            new String[] { NAME },    // 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);

              //  Spinner spinner = (Spinner) findViewById(R.id.spnMusketeers);

                // Populate your custom view here
                ((TextView)v.findViewById(R.id.payment_method1)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(NAME1) );
                ((TextView)v.findViewById(R.id.payment_method)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(NAME) );
                ((TextView)v.findViewById(R.id.phone1)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(PHONE1) );
                ((TextView)v.findViewById(R.id.phone)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(PHONE) );
                ((TextView)v.findViewById(R.id.email1)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(EMAIL1) );
                ((TextView)v.findViewById(R.id.email)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(EMAIL) );

                ((TextView)v.findViewById(R.id.firstname)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(FNAME) );
                ((TextView)v.findViewById(R.id.firstname1)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(FNAME1) );
                ((TextView)v.findViewById(R.id.total1)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(TOTAL1) );
                ((TextView)v.findViewById(R.id.total)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(TOTAL) );
                ((TextView)v.findViewById(R.id.lastname)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(LNAME) );
                ((TextView)v.findViewById(R.id.lastname1)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(LNAME1) );


                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;
        }
    });


}} 

ここで、出力を次の形式で表示したいと思います。

---->Orderinfo
            * payment_method
            * total
---->Customerinfo
         ---->Personalinfo
            * firstname
            * lastname
         ----->Contactinfo
            * phone
            * email

ここで私はこれを開発することはできません。

ここでコードを実装するにはどうすればよいですか???

ここでは、グループを作成するために headerData(orderinfo,customerinfo) と group2data(personalinfo,contactinfo) を作成しました。ここでは、以下のコードでのみ headerData を使用しました。

setListAdapter( new SimpleExpandableListAdapter(
            this,
            headerData,
            R.layout.group_row,
            new String[] { NAME },    // the names of the data
            new int[] { R.id.order },
            // the text field to populate with the field data
            childData,

したがって、orderinfo および customerinfo グループのみを作成しました。しかし、ここに group2data を追加することはできません。ここで、この行に groupdata を追加すると、次のエラーが発生したことを意味します。

- ブレークポイント:SingleMenuItemActivity - 行ブレークポイント:SingleMenuItemActivity [行: 134] - onCreate(Bundle) - コンストラクター SimpleExpandableListAdapter(SingleMenuItemActivity, ArrayList>, ArrayList>, int, String[], int[], ArrayList>>, int, null, int[]) は未定義です

エラーを解決するにはどうすればよいですか。助けてください。

4

1 に答える 1

0

ListView 内の ListView は非常に複雑です。OS には、スクロールするリストビューを特定するのに問題があります。

とにかく、パラメータリストを再確認する必要があるようです。そのオブジェクトのコンストラクターと一致することを確認してください。

于 2012-09-17T12:38:25.270 に答える