I'm writing an activity to list a bunch of items from the database and show an additional column with a quantity. I implemented an ArrayAdapter to show my custom layout. Here is the code of the most important parts of the Adapter:
static class ViewHolder {
protected TextView text;
protected EditText editText;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.rowquantitylayout, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.label);
viewHolder.editText = (EditText) view.findViewById(R.id.editText);
viewHolder.editText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
Log.i(TAG, "Editable:" + s.toString());
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
public void onTextChanged(CharSequence s, int start,
int before, int count) {
}
});
view.setTag(viewHolder);
viewHolder.editText.setTag(list.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).editText.setTag(list.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(list.get(position).getDescription());
holder.editText.setText("" + list.get(position).getQuantity());
return view;
}
Now, when I try to focus the "EditText" it loses focus just after I clicked it. It shows the keboard and it even gets to the Log.i, but doesnt let me change the value since it is not focused.
Thanks for the help