1

我想在自定义适配器类我的代码中更改文本更改侦听器的editext值(带计算):

 public class Voucher_Detail_Adapter extends ArrayAdapter<Voucher_List_Details> {
        /*Context context; 
        int layoutResourceId;   
        ProgressDialog pd1;
        ArrayList<Voucher_List_Details> data1=new ArrayList<Voucher_List_Details>();
        boolean[] checkBoxState;
        static Voucher_List_Details data[] = null;*/

        /*static Context context;
        int layoutResourceId;
        static Voucher_List_Details data[] ;*/
        int deducted_balance,assqty;


        static Voucher_Detail_Adapter ab;
        int d;

        //Button b;

        String voucher_type, voucher_name;
        int voucher_price,voucher_balance, voucher_dist_id,vid1 ;

        private LoginDBAdapter mySQLiteAdapter;

        SimpleCursorAdapter cursorAdapter;


        static Context context;
        int layoutResourceId;
        static Voucher_List_Details data[] = null;
        public BookHolder holder = null;


        static Voucher_Detail_Adapter b;


        public Voucher_Detail_Adapter(Context context, int textViewResourceId,
                Voucher_List_Details[] objects) {
            super(context, textViewResourceId, objects);
            this.layoutResourceId = textViewResourceId;
            Voucher_Detail_Adapter.context = context;
            Voucher_Detail_Adapter.data = objects;

        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View row = convertView;
            // BookHolder holder = null;


            if (row == null) {
                LayoutInflater inflater = ((Activity) context).getLayoutInflater();
                row = inflater.inflate(layoutResourceId, parent, false);
                holder = new BookHolder();




                holder.vname = (TextView) row.findViewById(R.id.txtTitle1);
                holder.vtype = (EditText) row.findViewById(R.id.vtype);
                holder.vprice = (EditText) row.findViewById(R.id.vprice);
                holder.vbalance = (EditText) row.findViewById(R.id.vbal);
                holder.vdid=(EditText)row.findViewById(R.id.vdid);
                holder.qty=(EditText)row.findViewById(R.id.aqty);
                row.setTag(holder);
                Voucher_List_Details book_detail = data[position];


                holder.vname.setText(book_detail.getV_name());
            System.out.println("name"  +book_detail.getV_name());

                holder.vtype.setText(book_detail.getV_type());


                holder.vprice.setText(String.valueOf(book_detail.getV_price()));


                holder.vbalance.setText(String.valueOf(book_detail.getV_bal()));

                holder.vdid.setText(String.valueOf(book_detail.getV_did()));


                System.out.println("did"  +book_detail.getV_did());



                holder.qty.addTextChangedListener(new TextWatcher() {

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                        // TODO Auto-generated method stub


                    }

                    @Override
                    public void beforeTextChanged(CharSequence s, int start, int count,
                            int after) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void afterTextChanged(Editable s) {
                        // TODO Auto-generated method stub

                        //assqty=10;


                            deducted_balance=((Integer.parseInt(holder.vbalance.getText().toString()))-assqty);

                            System.out.println("qty"  +assqty +"deducted"  +deducted_balance);


                            Toast.makeText(getContext(),String.valueOf(deducted_balance), Toast.LENGTH_SHORT).show();

                            holder.vprice.setText(String.valueOf(deducted_balance));

                            //deducted_balance=holder.vprice.setText(String.valueOf(book_detail.getV_price());
                    }
                });         

            } else {
                holder = (BookHolder) row.getTag();
            }


            return row;

        }

        static class BookHolder {

            TextView vname;
            EditText vtype;
            EditText vprice;
            EditText vbalance;
            EditText vdid; 
             EditText qty;

        }

    }

请帮助我我的editext值没有改变它显示我设置的默认值。我想做一些计算并显示edittext中的值。我使用了settext方法但它没有工作谢谢

4

1 回答 1

0

尝试这个..........

 holder.qty.addTextChangedListener(new View.TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // TODO Auto-generated method stub


            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                                          int after) {
                // TODO Auto-generated method stub

            }

            @Override
            public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub

                //assqty=10;


                deducted_balance = ((Integer.parseInt(holder.vbalance.getText().toString())) - assqty);

                System.out.println("qty" + assqty + "deducted" + deducted_balance);

                Toast.makeText(getContext(), String.valueOf(deducted_balance),
                        Toast.LENGTH_SHORT).show();

                TextView vprice_textview =
                        (TextView) listview.getChildAt(position).findViewById(R.id.textviewid);

                vprice_textview.setText(String.valueOf(deducted_balance));


            }
        });
于 2013-09-24T10:20:07.043 回答