Skip to content Skip to sidebar Skip to footer

Highlight Listview Item At Creation Time Via Code

I would like to highlight the first row (0) of my ListView when I create the listView. I tried different ways (like you can see in the commented code), but nothing worked. It's st

Solution 1:

In getView method of listview's adapter class,take id of text from Layout file and apply background color to it.

for example,

public View getView(int position, View convertView, ViewGroup parent) {
         Viewv=null;

         Stringinflater= Context.LAYOUT_INFLATER_SERVICE;
            LayoutInflaterli= (LayoutInflater) my_ctx
                    .getSystemService(inflater);
            v = li.inflate(R.layout.layoutfile, parent, false);
                          if(position==0)
                           {

              TextViewtext= (TextView) findViewById(R.id.textView1);
              text.setBackgroundColor(Color.ANY_COLOR);
                            }
 }

Post a Comment for "Highlight Listview Item At Creation Time Via Code"