mDev :
Related to: https://stackoverflow.com/posts/60708673/edit
I have variable a
that is in loop, it change it value so
- a=mc
- a=dd
- a=jj
How can i split that values in different variables names ?
Like
- a0=mc
- a1=dd
- a2=jj
Using android java
This code is in loop
String a = imgDataUr.substring(6); //this changed with different value each time
ArrayList<String> list = new ArrayList<String>();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1,list);
Log.d("countries", a);
list.add(a);
simpleList.setAdapter(adapter);
the purpose of my question is to put different variable name each time in list.add(a);
like
list.add(a1); //for the 1st loop
list.add(a2); //for the 2nd loop ...
deHaar :
You are creating a new list in every iteration which then gets just a single item. In addition, you create an adapter each iteration and set the single-itened list.
Do it like this:
- create the list and the adapter before the loop
- in the loop, just add
a
to the list and maybe log it and - set the list to the adapter after the loop
That may fix the undesired behaviour of showing only the last of the desired items.
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=296525&siteId=1