列表视图与编辑文本onitemclick无法在android中工作

时间:2014-09-08 07:44:36

标签: android listview android-listview

我在列表视图中使用编辑文本,但listview onItemclick不起作用,当我点击列表项时,它不可点击

当我使用 android:focusable =“false”时         android:focusableInTouchMode =“false”编辑文字然后编辑文字未启用

请帮助我如何解决这个问题

我的Listview代码

 <LinearLayout 
        android:id="@+id/listlayout"
        android:layout_width="match_parent"   
        android:layout_height="match_parent"
       >

        <ListView
            android:id="@+id/createlist"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:cacheColorHint="#00000000"
            android:clickable="true"
            android:descendantFocusability="beforeDescendants"
            android:divider="#eeeeee"
            android:dividerHeight="1dip"
            android:scrollingCache="true"
            android:smoothScrollbar="true"
            android:transcriptMode="normal" >

        </ListView>

    </LinearLayout>

列出项目Xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:padding="18dip"
   >

    <TextView
        android:id="@+id/txtItemcode"
        android:layout_width="110dip"
        android:layout_height="fill_parent"
        android:layout_marginLeft="10dip"
        android:layout_marginTop="9dip"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:singleLine="true"
        android:text="323232"
        android:textColor="#0C090A"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/txtItem"
        android:layout_width="300dip"
        android:layout_height="fill_parent"
        android:layout_marginLeft="25dp"
        android:layout_marginTop="9dip"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:text="5456455565456"
        android:textColor="#0C090A"
        android:textSize="20sp" />

    <EditText
        android:layout_marginTop="4.5dip"
        android:id="@+id/editcreateQuantity"
        android:layout_width="100dp"
        android:layout_height="50dip"
        android:background="@android:drawable/editbox_background"
        android:ems="10"
        android:inputType="number"
        android:singleLine="true"

       />

</LinearLayout>

我的Getview Java代码

// Create List Adapter

class CreateAdapter extends ArrayAdapter<String>  {
String[] strItecode=null;
String[] strItem;
String[] strQuantity;
Context context;

int temp;
CreateAdapter(Context context, String[] strItemcode, String[] strItem,
        String[] strQauntity) {
    super(context, R.layout.create_list_item, R.id.txtItemcode, strItemcode);
    this.context = context;
    this.strItecode = strItemcode;
    this.strItem = strItem;
    this.strQuantity = strQauntity;
   // text= new String[strItem.length];
}
private int editingPosition = 0;
private TextWatcher watcher = new TextWatcher() {
          public void onTextChanged(CharSequence s, int start, int before, int count) {
              text[editingPosition] = s.toString();
          }
          public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
          public void afterTextChanged(Editable s) { }
      };

public View getView( final int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    temp=position;
    LayoutInflater mInflater = (LayoutInflater) context
            .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    if (convertView == null) {

        holder = new ViewHolder();
        convertView = mInflater
                .inflate(R.layout.create_list_item, parent, false);

        holder.txtItecode = (TextView) convertView
                .findViewById(R.id.txtItemcode);
        holder.txtItem = (TextView) convertView
                .findViewById(R.id.txtItem);
        holder.editQuantity = (EditText) convertView
                .findViewById(R.id.editcreateQuantity);
        holder.editQuantity.setTag(position);

        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    holder.editQuantity.removeTextChangedListener(watcher);
   if(text[temp].contentEquals("0"))
       holder.editQuantity.setText("");
   else
    holder.editQuantity.setText(text[temp]);

    holder.editQuantity.setOnFocusChangeListener(new OnFocusChangeListener() {       
        public void onFocusChange(View v, boolean hasFocus) {
          if(hasFocus)
              {

                 editingPosition = position;


              }
        }
    });


    holder.editQuantity.addTextChangedListener(watcher);

    // The rest is good, just make sure to remove the call to setting the EditText's text at the end
    holder.txtItecode.setText(strItecode[position]);
    holder.txtItem.setText(strItem[position]);
  //  holder.editQuantity.setText(text[temp]);

    return convertView;


}

class ViewHolder {
    TextView txtItecode;
    TextView txtItem;
    EditText editQuantity;
}

}

先谢谢

1 个答案:

答案 0 :(得分:0)

尝试更改值
     android:descendantFocusability="beforeDescendants"  到
    android:descendantFocusability="blocksDescendants"

希望对你有所帮助!