listview里面的Edittext没有关注焦点,也不让我编辑android

时间:2012-12-21 06:35:29

标签: android android-listview focus android-edittext

修改

现在已解决

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

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

enter image description here

Listview内的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>

这是listitems代码......

<?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;
    }

1 个答案:

答案 0 :(得分:0)

尝试添加

  

机器人:descendantFocusability = “blocksDescendants”

在list_item.xml的父布局