如何在编辑文本的自定义列表视图中输入值,当我选择第二个编辑文本时,我将丢失第一个编辑文本的值

时间:2017-07-17 12:16:56

标签: android listview android-custom-view

我使用了带有四个Edit文本的自定义列表视图,并设置了列表的限制。之后当我把值放在编辑文本中时,我选择一个编辑文本并输入值后我选择第二个编辑文本然后首先丢失他的值,我不能在列表中输入值:

  listView = (ListView) findViewById(R.id.listPrice);
     final int value = size;
            for (int i = 0; i < value; i++) {
                arrayList.add(i);
            }
      Button buttonAdd = new Button(this);
            buttonAdd.setText("ADD");
            listView.addFooterView(buttonAdd);
            customAdapter = new CustomAdapter(ProductSizePrice.this, 
R.layout.product_suze_detail, arrayList);
            listView.setAdapter(customAdapter);

自定义适配器

public class CustomAdapter extends ArrayAdapter {


    private List<Integer> list;
    private List<ShowProducts> listShowProducts;
    private Context context;
    private int resource;
    private String condition;
    String uri;
    int i = 0;

    public CustomAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<Integer> objects, String condition) {
        super(context, resource, objects);
        this.context = context;
        this.resource = resource;
        this.list = objects;
        this.condition = condition;
    }

    @Override
    public int getCount() {
        return super.getCount();
    }

    @Nullable
    @Override
    public Object getItem(int position) {
        return super.getItem(position);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        //    SurgicalonDetail surgicalonDetail=list.get(position);

        View view = LayoutInflater.from(context).inflate(resource, parent, false);
        if (condition == "Size_Price") {
            EditText size = (EditText) view.findViewById(R.id.etSize);
            EditText quantity = (EditText) view.findViewById(R.id.etQuantity);
            EditText price = (EditText) view.findViewById(R.id.etPrice);
            EditText cost = (EditText) view.findViewById(R.id.etCost);
            ConstraintLayout constraintLayout = (ConstraintLayout) view.findViewById(R.id.productSizePriceLayout);
        return view;

    }
}

从编辑文本中获取值

for (int i = 0; i < value; i++) {
                    View view = listView.getChildAt(i);
EditText etSize = (EditText) view.findViewById(R.id.etSize);
                    EditText etQuantity = (EditText) view.findViewById(R.id.etQuantity);
                    EditText etPrice = (EditText) view.findViewById(R.id.etPrice);
                    EditText etCost = (EditText) view.findViewById(R.id.etCost);
String sizeShow = etSize.getText().toString();
                    String quantityShow = etQuantity.getText().toString();
                    String priceShow = etPrice.getText().toString();
                    String costShow = etCost.getText().toString();

 arrayListSize.add(sizeShow.toString());
                        arrayListQuantity.add(Integer.parseInt(quantityShow.toString()));
                        arrayListPrice.add(Integer.parseInt(priceShow.toString()));
                        arrayListCost.add(Integer.parseInt(costShow.toString()));

0 个答案:

没有答案