问题
I have variable a in a loop, it gives a different string each time
I want to add that string in ListView
, without overwriting it, i searched for append ListView
, but didn't find anything, i always got the last item which is the last a value in the ListView
I think I need to use HashMap
or foreach, but i don't know how
in the image, each line is string a
variable, so the variable will change every time
158 word
here's my code
ArrayList<String> list = new ArrayList<String>();
ArrayAdapter<String> adapter=new ArrayAdapter<String>(getContext(),android.R.layout.simple_list_item_1,list);
list.add(a);
simpleList.setAdapter(adapter);
UPDATE:
code
a variable comes from console.log in javascript
siteView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessag) {
String imgDataUr= consoleMessag.message();
if (imgDataUr.contains("heyyes")) {
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);
}
return super.onConsoleMessage(consoleMessag);
}
});
来源:https://stackoverflow.com/questions/60708673/append-listview-with-the-same-variable-but-different-value-each-time