Reputation: 1
I have a little problem. When I select an item from a list is selected and is colored, until everything is right. Then when I go to another activity and I come back I want the item in the list is selected again. To summarize select an item in the list is reloaded when the activity, the ListView must know the item you want to click the loading for MonoDroid
Sorry for the bad English, I hope I explained. Thanks
Upvotes: 0
Views: 143
Reputation: 24460
The functionality you want is not normal behavior of Android, when the phone is in Touch Mode when and uses API level of less than 11.
So the easiest way is to target your application for API 11 or higher and add the following to your list item layout:
android:background="?android:attr/activatedBackgroundIndicator"
You also have to set ChoiceMode
on your list view:
listView.ChoiceMode = ChoiceMode.Single;
Now to remember the position of the item selected for when returning to the ListView
you need to save it somewhere. So in the ItemClick
event handler you could save the position to the SharedPreferences
like so:
var prefs = GetPreferences (FileCreationMode.Append);
var editor = prefs.Edit();
editor.PutInt("ListViewSelectedItem", args.Position);
editor.Commit();
And to set the highlighted item when coming back to the Activity with the ListView
you could place the following code in OnResume
:
var prefs = GetPreferences(FileCreationMode.Append);
var val = prefs.GetInt("ListViewSelectedItem", 0);
listView.SetItemChecked(val, true);
Given that listView
is accessible from the OnResume
method.
Upvotes: 1