I am very new to android. My project requires me to create a list view and change multiple pieces of data in other views based on the user’s selection. So, say I choose a person’s name from the list. I want to change an ImageButton image, a TextView, and connect an array for that specific person. I’ve been using text processing on the string of the user’s selection and making sure my resources match a certain format. But, I feel there should be a better way. If you can’t tell already, I am also very new to programming.
I am looking for the simplest, but somewhat efficient solution to this.
EDIT: Here is some code WRT an List with an array called people:
// Handles User Selection of People
peopleList.setOnItemClickListener( new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Get Selection String
person1SavedText = people[position];
// Modify String to match corresponding resources and values
String people1ImageParsed = person1SavedText.toLowerCase().replace(" ", "").replace("-", "");
// Person 1 Image Uri/String
person1ImageUriString = "android.resource://org.example.person/drawable/" + person1ImageParsed;
person1ImagePath = Uri.parse(person1ImageUriString);
// Person 1 Array Uri/String
person1ArrayUriString = "android.resource://org.example.person/values/" + person1ImageParsed;
}
}
Sounds like you need to store temporary information based on a selection, then lookup data based on that selection, correct? I would use the built-in android preferences to store the selected item index (or other means of idntification) then lookup the ImageButton image, textview etc based on the value that is store in preferences. The preferences are available to everything withing the application if setup properly.
Shared Preferences details:http://developer.android.com/guide/topics/data/data-storage.html#pref
Google for “android sharedPreferences examples” for more assistance.
Best!