java - ARRAY ITEMS WITH INCREASING INDEX It's simple and I don't know how -


i have code in eclipse developing , android application need have items display in spinner. manage have items displayed in spinner code below bulky , let's have 100 items need have 100 of (item_food[n] +" "+ item_kcal[n] + "kcal")...this can basic logic or iq, don't know how. there function can use replace code within {} in code below? please help. thank in advance.

   string[] item_food = res.getstringarray(r.array.items_food);    string[] item_kcal = res.getstringarray(r.array.items_kcal);    display = new string[] { (item_food[0]+" " + item_kcal[0] + "kcal"),             (item_food[1] +" "+ item_kcal[1] + "kcal"),             (item_food[2] +" "+ item_kcal[2] + "kcal"),             (item_food[3] +" "+ item_kcal[3] + "kcal"),             (item_food[4] +" "+ item_kcal[4] + "kcal"),             (item_food[5] +" "+ item_kcal[5] + "kcal") }; 

yes. can loop. first length, minimum of 2 source arrays length. construct new string[] of length. loop on 2 input arrays , assign new value output slot of array. like

int len = math.min(item_food.length, item_kcal.length); display = new string[len]; (int = 0; < len; i++) {     display[i] = string.format("%s %skcal", item_food[i], item_kcal[i]); } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -