4
我有一个列表视图,其中包含一个edittext在每一行。当我在列表视图的最后一行添加文本时,我想向列表视图添加一个空行。所以我改变我的列表并调用notifyDataSetChanged()。不幸的是焦点转移到了listview以外的地方。我如何将焦点保留在我目前的edit_text中?我试过edit_text.requestFocus() - 但它不起作用。焦点失去了notifyDataSetChanged()
代码:
@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();
// How to keep the focus? edit_text.requestFocus(); did not help
}
}
// ..
return rowView;
}
}
THX!
同样的问题在这里。 –