I have a listview that contains edittext in each row. When I add text to the last line of the list, I want to add an empty line to the list. So I change my list and call notifyDataSetChanged (). Unfortunately, the focus is on a place outside the list. How to keep focus in current edit_text? I tried edit_text.requestFocus () - but that didn't work.
code:
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView=inflater.inflate(R.layout.design_listview, parent, false);
EditText edit_text=(EditText) rowView.findViewById(R.id.list_edittext);
edit_text.setText(values.get(position).text);
edit_text.addTextChangedListener(new TextWatcher()
{
public void beforeTextChanged(CharSequence charSequence, int i, int j, int k) { }
public void onTextChanged(CharSequence charSequence, int i, int j, int k) { }
public void afterTextChanged(Editable editable)
{
values.get(position).text=editable.toString();
if(position == values.size()-1 && editable.toString().length() > 0) {
listaddItem();
notifyDataSetChanged();
}
}
return rowView;
}
}
thanks!
source
share