如何在运行时将expandText设置为expandablelistActivity?

时间:2011-06-11 10:47:37

标签: android text edit expandablelistview

这里是我在kist视图中尝试在运行时设置文本的代码,但是当我尝试扩展新的父级时它会被更改.... 下面是我的代码

SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(
    this, createGroupList(), // groupData describes the first-level
                         // entries
    R.layout.catagory_group_row, // Layout for the first-level
                                 // entries
    new String[] { "catagoriesName" }, // Key in the groupData maps
                                       // to display
    new int[] { R.id.childname }, // Data under "catagoriesName" key
                                  // goes into this TextView
    createChildList(), // childData describes second-level entries
    R.layout.catagory_child_row, // Layout for second-level entries
    new String[] { "ItemsName", "desc" }, // Keys in childData maps
                                          // to display
    new int[] { R.id.menu, R.id.quantity } // Data under the keys
                                           // above go into these
                                           // TextViews
    );

    Log.i(LOG_TAG, "inside ExpandableList");
    setListAdapter(expListAdapter);
}

public boolean isChildSelectable(int groupPosition, int childPosition) {
    return true;
}

// Update the current state if changed
@Override
public void onContentChanged() {
    super.onContentChanged();
    Log.d(LOG_TAG, "onContentChanged");
}

@Override
public boolean onChildClick(ExpandableListView parent, View v,
        int groupPosition, int childPosition, long id) {

    Log.d(LOG_TAG, "onChildClick: " + childPosition);
    // final TextView text1 = (TextView) parent.
    // TextView textView=new TextView(Format.this);
    // parent.getItemAtPosition(childPosition);
    int i = childPosition;
    text = (TextView) v.findViewById(R.id.quantity);
    CheckBox cb = (CheckBox) v.findViewById(R.id.check1);
    tvMenuName = (TextView) v.findViewById(R.id.menu);
    tvDescName = (TextView) v.findViewById(R.id.desc);

    /*
     * Show DialogBox for Enter User Input
     */

    final AlertDialog.Builder alert = new AlertDialog.Builder(this);
    final EditText input = new EditText(this);
    alert.setTitle("Enter Items Number to be Order");
    alert.setView(input);

    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton) {
            String value = input.getText().toString().trim();

            // text1.setText(value);
            // qty = value;

            try {
                String[] val = value.split("/");
                int quantity = Integer.parseInt(val[0]);
                tvDescName.setText(value);
                OrderlistData data = new OrderlistData(tvMenuName.getText()
                        .toString(), value);
                orderlist.add(data);
                // qty="";
            } catch (Exception e) {
                System.out.println("enter a valid quantity");
            }

        }
    });

    alert.setNegativeButton("Cancel",
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            });

    /**
     * Getting Orderlist Data from Customer
     */

    alert.show();

    // return(true);
    if (cb != null) {
        cb.toggle();
        /*
         * if(tvDescName.getText()!="") cb.setChecked(true); else
         * cb.setChecked(false);
         */
    }

    return true;

}

0 个答案:

没有答案