I have a listview consists of TextView, EditText and Checkbox. the layout of each item in the listview is shown below. the problem i have now is that i can not edit the editText, when i touch the editText to edit it the cursor jumps away and i can not edit the value inside the editText.
to solve thi problem, i referred to some posts and I added the following two line to the EditText
android:focusable="true"
android:focusableInTouchMode="true"
but it did not solve the problem
please also have alook at the getView() method is is posted below.
please let me know how to solve this problem to edit the EditText
item layout
<?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;
}