Josh Dobbs wrote:
> Can you elaborate on building a map or point me to the correct
> documentation.
You indicated you wanted to be able to find a View by some String name.
Since Views are not stored anywhere by a String name, you will have to
make this mapping yourself. The standard Java interface for mapping one
value to another is java.util.Map, and the typical implementation of
that is java.util.HashMap.
Map<String, Integer> widgetsByName=new HashMap<String, Integer>();
widgetsByName.put("why", R.id.btn1);
widgetsByName.put("you", R.id.btn2);
widgetsByName.put("want", R.id.btn4);
widgetsByName.put("this", R.id.btn5);
widgetsByName.put("is", R.id.btn5);
widgetsByName.put("beyond", R.id.btn6);
widgetsByName.put("my", R.id.btn7);
widgetsByName.put("understanding", R.id.btn8);
(where you would use your own String names and widget IDs)
Then, sometime later, given a String name, you could:
Button btn=(Button)findViewById(widgetsByName(name));
> What advantaged does a map have over an array?
In Java, arrays are indexed by integers, not Strings.
--
Mark Murphy (a Commons Guy)
http://commonsware.com
Android Training on the Ranch! -- Mar 16-20, 2009
http://www.bignerdranch.com/schedule.shtml
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---