0

I hava listview which is in sidebar. This listview has 5 items and for click on each item an new activity is launched . So , this sidebar listview also is part of that activity . I cannot use CLick Listener event to highlight listview since each click launches an completely new activity and hence a new view. The only option seems to be to highlight the item in listview in ONcreate() Event or some other hack.

How can i create an highlight an item in listview when the listview itself is replaced on each click on listview item

raghu_3
  • 1,849
  • 3
  • 18
  • 29

2 Answers2

0

You are going to want to write a custom list adapter. Extend a custom class from base adapter. The override the getView(...) function. Inside the getView you can check for a condition and then highlight the item/changebackground/etc

Alex
  • 271
  • 3
  • 8
0

Assuming the sidebar ListView is the same for each activity, then it should be a simple matter of passing the index of the ListView item that was selected to the new activity. Then in the new activity's onCreate, highlight the correct item in the ListView. I'll leave the implementation up to you but it should be fairly straightforward.

btse
  • 7,811
  • 3
  • 25
  • 30
  • I can do that but where should i set background color ? App crashing if i do that in Oncreate() because apparently the view is not fully formed when i set the background color of listitem. – raghu_3 Oct 02 '13 at 01:10
  • @james234 How are you currently doing it? If you google around there are a bunch of different ways of doing it. Here http://stackoverflow.com/questions/10788688/programmatically-select-item-listview is one of them. What error are you getting? You should be able to make changes to the View in `onCreate()`. – btse Oct 03 '13 at 21:22