Tuesday, 17 September 2013

findViewById in android doesn't return child layout

findViewById in android doesn't return child layout

I inflate a view. Using the newly created layout, I find a child to set a
property. But the child I get (mealName here) is not the good one. Having
my mealList containing multiple mealName, it's always the first one that
is returned.
RelativeLayout mealNameLayout = (RelativeLayout)
inflater.inflate(R.layout.planner_list_item_meal_title, mealList);
TextView mealName = (TextView) mealNameLayout.findViewById(R.id.mealName);
//Set meal name.
mealName.setText(meal.name);
By making this modification (not attaching automatically the relative
layout to the list):
RelativeLayout mealNameLayout = (RelativeLayout)
inflater.inflate(R.layout.planner_list_item_meal_title, mealList, false);
I'm having better results, but still very weird behavior. Looks like using
findViewById when having multiple items with the same id is not a good
idea. Even though there is only one item having this id in the children.
Any idea on what's going on?

No comments:

Post a Comment