开发者

How to set focus on a particular item in listview. Android?

I have a listview with edittext in each row. This is to implement a to do list. When the user is in the second row and press the enter key, I want to add a row and give focus to the new row with keyboard enabled. So that he can immediately start to type on the new row. I was able to capture the onkey press in the edit text and then add a new row to the adapter and notifyDataSetChanged() so that the list view is refreshed. But after this is am not able to bring the focus to the new row. It goes to the first row, or sometimes does not have focus at all, or sometimes works fine.

Please let me know if there is any work around for this. Or let me 开发者_JS百科know if I am totally wrong in going for a list view to implement the todo/check list. Thank you for your time and advice.


Capture the Cursor from bindView() when the button is clicked and store it in let's say, tempCursor.

After calling notifyDataSetInvalidated(), get the position from the tempCursor and set this position in the ListView.

    refreshList();

    listView.setSelection(tempCursor.getPosition());


im not sure if this is what you are looking for.

to select a listItem there is this setSelection, setSelectionAfterHeaderView, setSelectionFromTop.. Link .

and for getting focus on views this is a requestFocus.. Link

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜