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!
同樣的問題在這裏。 –