Glue background in Listview getView(s) using SimpleAdapter filter



  • It was a difficult question.

    I'll use it. listView c simpleAdapter♪ For the purpose of filling the back of the line getViewand use the list to filter lvadapter.getFilter().filter(s)

    When the list is downloaded, all the beckgrunts are properly and beautifully placed, and when they start filtering, the lines of the list are as good as they've been.

    lvadapter = new SimpleAdapter(
         ClientsListActivity.this, clientsList,
         android.R.layout.simple_list_item_activated_2, new String[] {
             TAG_NAME, TAG_PHONE
         },
         new int[] {
             android.R.id.text1, android.R.id.text2
         }) {
         public View getView(int position, View convertView, android.view.ViewGroup parent) {
             View result = super.getView(position, convertView, parent);
             if (position == 0) {
                 result.setBackgroundColor(0x448FCC85);
             } else {
                 // set another background ... this is the default background, you have to provide this because the views are reused
             }
             HashMap < String, Object > itemHashMap = (HashMap < String, Object > ) lv.getItemAtPosition(position);
             boolean vip = ((boolean) itemHashMap.get("vip"));
             if (vip) {
                 result.setBackgroundColor(Color.rgb(245, 233, 234));
             }
             return result;
         }
     };
    

    I don't know what to do, please help me.



  • You don't just have to paint the rightvipbut also forcefully restore the old color to "negative"!vip- Use the design if - else to set both colours for the web.
    This is due to the fact that each web site reused in other positions and positions. !vip the one who was previously in position. vip (and vice versa):

    if (vip) {
              result.setBackgroundColor(Color.rgb(<vip_color>));
             }
      else {
            result.setBackgroundColor(Color.rgb(<normal_color>));
           };
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2