You should really create the text views dynamically, but just to get you started and answer your question, here is how you could do it if you always have a static amount of TextViews defined.
The key is that you need to reference each TextView defined in the layout xml separately.
You would need to define a TextView for each ingredient, and a TextView for each unit (in this case a total of 6 TextViews, 3 ingredients and 3 units).
ArrayList<Map<String, Object>> recipeIngredients = db
.getRecipeIngredients(recipeId);
int i = 0;
for (Map<String, Object> ingredient : recipeIngredients){
String ingredients = ingredient.get(RECIPES_INGREDIENTS.ingredientNeed).toString() + " "
+ ingredient.get(RECIPES_INGREDIENTS.ingredient).toString();
String unit = ingredient.get(RECIPES_INGREDIENTS.unit);
if (i == 0){
((TextView) findViewById(R.id.recipeIngredientsFirst)).setText(ingredients);
((TextView) findViewById(R.id.recipeUnitFirst)).setText(unit);
}
else if (i == 1){
((TextView) findViewById(R.id.recipeIngredientsSecond)).setText(ingredients);
((TextView) findViewById(R.id.recipeUnitSecond)).setText(unit);
}
else if (i == 2){
((TextView) findViewById(R.id.recipeIngredientsThird)).setText(ingredients);
((TextView) findViewById(R.id.recipeUnitThird)).setText(unit);
}
i++;
}
As you can probably see, it's going to get messy quickly.
You probably won't have the same number of ingredients in each recipe, so you don't want to have the layout set in stone in the layout xml.
It might be better to use a ListView and ListAdapter.
Take a look at this tutorial:
http://www.vogella.com/tutorials/AndroidListView/article.html