开发者

Android ListView programmatic selection/highlight

I have a simple listview and listadapter setup as follows:

listAdapter = new ArrayAdapter<MyDomainObject>(this, android.R.layout.simple_list_item_1, listOfDomainObjects);
lis开发者_JAVA百科tView.setAdapter(listAdapter);

The user makes a selection on the list which takes them to another activity. From the new activity they can click their selection which returns them to the activity with the above list. I want to highlight the previous selection made. I currently find the matching list entry and call:

listView.setSelection(matchIndex);

This brings their previous selection to the top of the list. Is it possible to highlight (in that default orange) the previous selection. I have tried several approaches with no luck.


What you have is fine. However, the determination of whether the selection is "highlighted" is determined on whether the user was using the touchscreen. If they have used the touchscreen more recently than the trackball/D-pad/whatever, the device is in "touch mode" and selection highlights are not shown.


use simple_list_item_activated_1 you're using simple one.

Also to highlight selected row use this code

listview.setItemChecked(position, true);

position refers to row id you want to select.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜