java - Setting ListView backgroundColors after some action -


i'm wondering best way change colours of listview in android. here basic explanation of happening, im getting data list , populating it, run sentiment analysis api against text of listview, in onpostexecute of sentiment gathering want change colours on listview green positive or red negative.

i'm going through list of strings in onpostexecute method , adding values of positive, negative , neutral this.

                for(int index = 0; index<sentiments.size();index++)         {             if(sentiments.get(index).contains("positive"))             {                 occurrencespos++;                       //viewtweet.getchildat(index).setbackgroundcolor(color.green);              }             if(sentiments.get(index).contains("negative"))             {                 occurrencesneg++;              }             if(sentiments.get(index).contains("neutral"))             {                 occurrencesneu++;             } 

please note commented out line not work me works children visible entities i.e. first 5 have lists going upwards of 50 sometimes. required effect if search list of 5 data items.

the list being populated follows: carried out in seperate asynctask in onpostexecute method.

    arraylist<map<string, string>> list = builddata();        string[] = { "name", "content" };        int[] = { android.r.id.text1, android.r.id.text2 };         simpleadapter adapter = new simpleadapter(activity, list,            layout.list_layout, from, to);        setlistadapter(adapter);         // creation of content added displayed in list      private arraylist<map<string, string>> builddata() {        arraylist<map<string, string>> list = new arraylist<map<string, string>>();        for(int = 0;i<tweetcontent.size();i++)        {        list.add(putdata("@"+usernames.get(i),tweetcontent.get(i)));        }        return list;      }       private hashmap<string, string> putdata(string string, string string2) {        hashmap<string, string> item = new hashmap<string, string>();        item.put("name", string);        item.put("content", string2);        return item;      } 

so in short happening, grabbing tweets twitter using api call passing values 2 string lists tweetcontent , username used populate list, once list populated call 2nd async task calls sentiment analysis api, put results new string list , count number of pos,neg,neu occurences pass graph, want update list colors match these positive negative , neutral values 2nd onpostexecute, possible?

why don't create array , store colors of each item in it, , in view assign color bg color.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -