Append listview with the same variable but different value each time

狂风中的少年 提交于 2021-01-29 14:52:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!