只有第一个EditText正在更新

时间:2014-08-18 13:04:15

标签: android android-layout dynamic android-edittext

我正在尝试根据EditText(for Unit Price)中的所选项目更新Spinner

Dynamic Addition of data

正如您在上图所示,每plus ButtonLayout(Spinner, Button and two EditText)都会添加一个。{/ p>

因此,当添加第一个Layout时,EditText(for "Unit Price")会在微调器中显示所选产品的值,但是当我添加更多布局时,Unit Price不会在新{{1}中更新此外,当我更改任何EditText的所选项时,更新了第一个Spinner的值。

这是我的代码: -

EditText

2 个答案:

答案 0 :(得分:0)

最后通过使用以下方法解决了问题: -

            s = (Spinner) newView.findViewById(R.id.spinner1);  
            //newView was missing earlier in the line below      
            unitprice = (EditText) newView.findViewById(R.id.editPrice);  

            try {
                loadSpinnerData(s);
                s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                    @Override
                    public void onItemSelected(AdapterView<?> arg0, View arg1,
                            int arg2, long arg3) {

                        String selecteditem = s.getSelectedItem().toString();
                        try {
                            loadUnitPrice(selecteditem, unitprice);
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }


                    }

                    @Override
                    public void onNothingSelected(AdapterView<?> arg0) {
                        // TODO Auto-generated method stub

                    }

                });
            } catch (IOException e) {
                //TODO: catch exception
                e.printStackTrace();
            }

<强> loadUnitPrice(): -

private void loadUnitPrice(String selectedItem, EditText unitprice) throws IOException {
        DBHelper db = new DBHelper(getApplicationContext());

        String price = db.getUnitPrice(selectedItem);
        System.out.println(price);

        unitprice.setText(price);   
    }

答案 1 :(得分:-1)

我认为问题是你的EditText代码中有重复的id。您可以检查每个EditText是否有唯一的ID