如何动态地在可扩展列表项中放置文本?

时间:2011-08-04 12:27:15

标签: android expandablelistview

我有一个应用程序,我需要在运行时动态输入文本? 请说我怎么办? 我在下面尝试过但是当我扩展其他父母时它改变了。 谢谢你

    @Override
    public View getChildView(final int groupPosition,
            final int childPosition, boolean isLastChild, View convertView,
            ViewGroup parent) {

        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.showcat_sub, null);
        }

        final TextView tt = (TextView) v.findViewById(R.id.showMenuName);
        final TextView tv = (TextView) v.findViewById(R.id.showQty);

        //final CheckBox cb1 = (CheckBox) v.findViewById(R.id.chkShowItems);
        //ImageView img = (ImageView) v.findViewById(R.id.imgShowItems);

        tt.setText(getChild(groupPosition, childPosition).toString());
        tt.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);

        if (y == groupPosition && z == childPosition && y != 0) {
            tt.setBackgroundColor(Color.MAGENTA);
        } else {
            tt.setBackgroundColor(Color.TRANSPARENT);
        }

        tt.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                y = groupPosition;
                z = childPosition;


            /*  
                List<HashMap<String, String>> curList=list.get(groupPosition);
                final HashMap<String, String> map=curList.get(childPosition);


                tvMenuName = (TextView) v.findViewById(R.id.menu);
                tvDescName = (TextView) v.findViewById(R.id.desc);


                */








                     final Dialog dialog = new Dialog(CategoriesActivity.this);
                    dialog.setContentView(R.layout.text_enter_dialog);
                    dialog.setTitle("Enter Quantity");

                    final EditText input = (EditText) dialog.findViewById(R.id.edCategoryDialog);
                    final EditText by = (EditText) dialog.findViewById(R.id.edByCategoryDialog);
                    Button okButton = (Button) dialog.findViewById(R.id.btnAddCategoryDialog);

                    System.out.println("inside dialog_started");

                    okButton.setOnClickListener(new OnClickListener() {
                        public void onClick(View arg0) {

                            System.out.println("inside dialog_started  ok");
                            String value="";
                            String value1 = input.getText().toString().trim();
                            String value2 = by.getText().toString().trim();
                            if(value2!=""&&!value2.equals("")){
                             value=value1+"/"+value2;
                            }
                            else{
                                 value=value1;
                            }

                            try {

                            /*  
                                text.setText(value);
                                color.setText("selected");
                                color.setBackgroundColor(Color.LTGRAY);

                                OrderlistData data = new OrderlistData(tvMenuName.getText()
                                        .toString(), value1);


                                 if(orderlist1.contains(data)){
                                        orderlist1.remove(data);
                                    }

                                boolean b=checkExistence(tvMenuName.getText().toString(),value1);
                                if(b)

                                    orderlist1.add(data);

                            */
                                //map.put("qty",value);

                                tv.setText(getChild(groupPosition, childPosition).toString()+value);                    

                            } catch (Exception e) {
                                Toast.makeText(CategoriesActivity.this, "Enter a valid quantity.....", Toast.LENGTH_LONG);
                            }



                              dialog.dismiss();
                            // app specific code
                        }


            private boolean checkExistence(String string,String value1) {
                 try {
                     HashMap<Integer, List<OrderlistData>> orederMap = ConText
                        .getContextMap();
                       List<OrderlistData> orderlist4 = orederMap.get(ConText.currentPos);
                       for (OrderlistData orderlistData : orderlist4) {
                           orderlistData.setNoOfItems(value1);
                        if(orderlistData.getItemName().equals(string)){
                            return false;
                        }
                    }


                } catch (Exception e) {
                    System.out.println("error is ......."+e);
                }
                return true;

            }

                    });
                    Button cancelButton = (Button) dialog.findViewById(R.id.btnCancelCategoryDialog);
                    cancelButton.setOnClickListener(new OnClickListener() {
                        public void onClick(View arg0) {
                            dialog.dismiss();
                        }           
                    });

                    dialog.show();


            }
        });




        return v;
    }

0 个答案:

没有答案