无法根据位置将edittext值设置为textview

时间:2014-11-25 04:41:20

标签: android

我在列表视图中有一个编辑文本。每次listview的编辑文本值都更新到数据库中。我在db中也有配方数量(编辑文本值)和配方价格。我得到这些价格并保存在setprice变量中。但现在我正在尝试按照列表视图位置将这些值设置为文本视图。但我能够将倍数值设置为它所希望的正确位置

     quantityt.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start,
                int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start,
                int before, int count) {
            valueList[position] = s.toString();
            Log.e("", "-----value list of position----"
                    + valueList[position]);
            quantityval = valueList[position];
            Log.e("", "quantityval-----" + quantityval);
            int selectedid = getid.get(position);
            Log.e("", "selectedid-----" + selectedid);
            te=db.update(quantityval, selectedid);
            Log.e("", "te----" + te);
            int getprice = pricesarray.get(position);
            setprice = getprice * te;
            Log.e("", "---set price value---" + setprice);
            int id = (int) list.getItemIdAtPosition(position);
             lContact.setExt(setprice);

            // Log.e("", "lcontact.getExt value---"+lContact.getExt());
            holder.setprice.setText(String.valueOf(setprice));



        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

1 个答案:

答案 0 :(得分:1)

尝试使用以下代码:

quantityt.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start,
                int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start,
                int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
valueList[position] = s.toString();
            Log.e("", "-----value list of position----"
                    + valueList[position]);
            quantityval = valueList[position];
            Log.e("", "quantityval-----" + quantityval);
            int selectedid = getid.get(position);
            Log.e("", "selectedid-----" + selectedid);
            te=db.update(quantityval, selectedid);
            Log.e("", "te----" + te);
            int getprice = pricesarray.get(position);
            setprice = getprice * te;
            Log.e("", "---set price value---" + setprice);
            int id = (int) list.getItemIdAtPosition(position);
             lContact.setExt(setprice);

            // Log.e("", "lcontact.getExt value---"+lContact.getExt());
            holder.setprice.setText(String.valueOf(setprice));
        }
    });