1

编辑

现在解决了

当我在 Adapter 类中删除 addTextChangeLister 时,editext 将成为焦点,它让我可以编辑值,但是addTextChangeListener当用户输入时如何添加以计算报价的值。

我在列表项中有 2 个Editext(数量和价格)和一个TextView(报价)。我希望用户可以输入价格和数量,然后在用户更改两个值(数量或价格)中的任何一个时计算报价Edittext。这是屏幕截图

在此处输入图像描述

但是Editext里面Listview没有关注,不要让我编辑它这是代码......

这是列表视图 xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <EditText
        android:id="@+id/ep_multiselect"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:completionThreshold="3"
        android:hint="Enter Product Name"
        android:textSize="16sp" />

    <Button
        android:id="@+id/ep_go"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/ep_multiselect"
        android:text="   Go   " />

    <ListView
        android:id="@+id/ep_listview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ep_go"
        android:focusable="false"
        android:visibility="gone" >
    </ListView>

</RelativeLayout>

这是列表项代码...

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/ep_productName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="3dip"
        android:layout_toLeftOf="@+id/ep_checkBox"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/ep_qty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/ep_productName"
        android:layout_toLeftOf="@+id/ep_price"
        android:ems="10"
        android:focusable="true"
        android:hint="Qty"
        android:inputType="number" >
    </EditText>

    <EditText
        android:id="@+id/ep_price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/ep_qty"
        android:layout_alignBottom="@+id/ep_qty"
        android:layout_alignParentRight="true"
        android:ems="10"
        android:focusable="true"
        android:hint="Price"
        android:inputType="number" />

    <TextView
        android:id="@+id/ep_quotePrice"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/ep_qty"
        android:text="Quote Price"
        android:textSize="16sp" />



</RelativeLayout>

这就是我在java中处理它的方式..

private class MyEditProductAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private ArrayList<ProductDetailBean> productDetails;

    private boolean listType;

    public MyEditProductAdapter(LayoutInflater arg1,
            ArrayList<ProductDetailBean > productDetails,
            boolean listType) {
        this.inflater = arg1;

        this.productDetails = productDetails;
        this.listType = listType;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return productQuantity.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return productQuantity;
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup arg2) {
        final Holder holder;
        if (convertView == null) { 
            holder = new Holder();

            // inflate the view from xml
            convertView = inflater.inflate(R.layout.edit_product_listitems,
                    null);


            holder.productName = (TextView) convertView
                    .findViewById(R.id.ep_productName);
            holder.qty = (EditText) convertView.findViewById(R.id.ep_qty);
            holder.quotePrice = (TextView) convertView
                    .findViewById(R.id.ep_quotePrice);
            holder.price = (EditText) convertView
                    .findViewById(R.id.ep_price);

            holder.box = (CheckBox) convertView
                    .findViewById(R.id.ep_checkBox);

            holder.qty.addTextChangedListener(new TextWatcher() {

                @Override
                public void onTextChanged(CharSequence arg0, int arg1,
                        int arg2, int arg3) {
                    if (arg0.length() > 0) {
                        holder.quotePrice.setText("Quote Price : "
                                + Integer.parseInt(arg0.toString())
                                * productPrice.get(position));
                        notifyDataSetChanged();
                    }
                }

                @Override
                public void beforeTextChanged(CharSequence arg0, int arg1,
                        int arg2, int arg3) {
                    // TODO Auto-generated method stub

                }

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

                }
            });

            holder.price.addTextChangedListener(new TextWatcher() {

                @Override
                public void onTextChanged(CharSequence arg0, int arg1,
                        int arg2, int arg3) {
                    if (arg0.length() > 0) {
                        holder.quotePrice.setText("Quote Price : "
                                + Integer.parseInt(arg0.toString())
                                * productQuantity.get(position));
                        notifyDataSetChanged();
                    }
                }

                @Override
                public void beforeTextChanged(CharSequence arg0, int arg1,
                        int arg2, int arg3) {
                    // TODO Auto-generated method stub

                }

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

                }
            });

            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }

        final int localproductPrice = this.productPrice.get(position);
        final int localqty = this.productQuantity.get(position);
        holder.productName.setText(this.productName.get(position));
        holder.qty.setText("" + localqty);
        holder.price.setText("" + localproductPrice);
        holder.quotePrice.setText("Quote Price : "
                + (localqty * localproductPrice));

        return convertView;
    }
    }

    static class Holder {
        TextView productName, quotePrice;
        CheckBox box;
        EditText qty, price;
    }
4

1 回答 1

0

尝试添加

android:descendantFocusability="blocksDescendants"

在 list_item.xml 的父布局中

于 2012-12-21T06:46:36.937 回答