Scroll down for my answer. The question doesn't really matter and the code is just confusing.
Is there a function that will allow me to fetch the id labels so I can loop a button listener easily? Currently I have in my main "container" xml that houses fragments this line of code:
public static final Map<String, Integer> RMAP = createMapR();
// Map of widget id's in R
private static Map<String, Integer> createMapR() {
Map<String, Integer> result = new HashMap<String, Integer>();
for (Field f : R.id.class.getDeclaredFields()) {
String key = f.getName();
Integer value = 0;
try {
value = f.getInt(f);
}
catch (IllegalArgumentException e) {
e.printStackTrace();
}
catch (IllegalAccessException e) {
e.printStackTrace();
}
result.put(key, value);
}
return Collections.unmodifiableMap(result);
}
and then one of my fragments will pick up the RMAP, and cross that with the labels I have specified. I'm doing this because I have a few buttons and specifying a huge list of listeners seemed inefficient, then I got sidetracked on this code.
public class BottomFragment extends Fragment {
private final String[] LABELS = {"button_do_1", "button_woah_2", "button_foo_1",
"button_hi_2"};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.bottom_fragment, container, false);
for (String item : LABELS) {
if (Container.RMAP.containsKey(item)) {
((Button) v.findViewById(Container.RMAP.get(item)))
.setOnClickListener(this);
}
}
return v;
}
However if there was a way to iterate through the list of android:id items specifically to BottomFragment() I wouldn't have to even need the first block of code and it would eliminate the manual list of ID's I've typed in.