2017-02-12 73 views
0

我有一个列表视图由TextView,EditText和复选框组成。下面显示了列表视图中每个项目的布局。我现在的问题是,我不能 编辑editText,当我触摸editText进行编辑时,光标跳过,我无法编辑editText中的值。如何编辑EditText

解决THI问题,我提到了一些帖子,我添加了以下两个线对的EditText

android:focusable="true" 
android:focusableInTouchMode="true" 

但它并没有解决问题

请也有alook在getView( )方法是张贴在下面。

请让我知道如何解决这个问题,编辑的EditText

项目布局

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

<TextView 
    android:id="@+id/tv" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1"/> 

<EditText 
    android:id="@+id/et" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:cursorVisible="true" 
    android:focusable="true" 
    android:focusableInTouchMode="true"/> 

<CheckBox 
    android:id="@+id/cb" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1"/> 

getView

@Override 
public View getView(final int position, View convertView, ViewGroup parent) { 
    // TODO Auto-generated method stub 

    View view = null; 

    if (convertView == null) { 
     LayoutInflater layoutinflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); 
     view = layoutinflater.inflate(R.layout.model, null); 

     final ViewHolder holder = new ViewHolder(); 

     holder.tv = (TextView) view.findViewById(R.id.tv); 
     holder.cb = (CheckBox) view.findViewById(R.id.cb); 
     holder.et = (EditText) view.findViewById(R.id.et); 

     holder.cb.setOnCheckedChangeListener(new OnCheckedChangeListener() { 

      @Override 
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
       // TODO Auto-generated method stub 

       ItemDesign element = (ItemDesign) holder.cb.getTag(); 
       element.setChecked(buttonView.isChecked()); 
      } 
     }); 

     holder.cb.setTag(designList.get(position)); 
     holder.et.setTag(designList.get(position)); 
     holder.tv.setTag(designList.get(position)); 
     //holder.et.setFocusable(false); 
     view.setTag(holder); 
    } else { 
     view = convertView; 
     ((ViewHolder)view.getTag()).et.setTag(designList.get(position)); 
     ((ViewHolder)view.getTag()).tv.setTag(designList.get(position)); 
     ((ViewHolder)view.getTag()).cb.setTag(designList.get(position)); 
     //((ViewHolder)view.getTag()).et.setFocusable(false); 
    } 
    ViewHolder holder = (ViewHolder) view.getTag(); 
    holder.tv.setText(designList.get(position).getTxt()); 
    holder.cb.setChecked(designList.get(position).isChecked()); 
    holder.et.setText(designList.get(position).getEtTxt()); 
    //holder.et.setFocusable(false); 
    return view; 
} 
private class ViewHolder { 
    TextView tv; 
    CheckBox cb; 
    EditText et; 
} 
+0

这可以帮助你http://stackoverflow.com/questions/9015853/android-how-to-make-edittext-editable-inside -a-listview –

回答

1

我个墨水你的问题与你添加的这三行代码无关

android:cursorVisible="true" 
android:focusable="true" 
android:focusableInTouchMode="true" 

你可以删除它们。问题在于这条线。您将EditText宽度设置为零。

android:layout_width="0dp" 

改变它,你是好去

android:layout_width="wrap_content" 
+0

不是在这种情况下,因为他使用的是布局权重,所以在这种情况下0dp的宽度是正确的。 – Booger

+0

@Mehran Zamani你的问题是发布的答案没有检查他给了layout_weigh –

+0

越狱定义android:layout_width似乎理性没有将其设置为0dp –