title: android set specific rows background of a listview with a color
body: <p>I am working on a listview, and would like to higlight, for example, row 3 to row 7 in the listview.</p>
  
  <h2>Code:</h2>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) 
  {   
      super.onCreate(savedInstanceState);
      setContentView(R.layout.sample_list);
      lv = (ListView) findViewById(R.id.sample_listview);
  
      String[] Sample_List = getResources().getStringArray(R.array.Sample_List);  
      final ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;();
      for (int i = 0; i &lt; Sample_List.length; ++i) 
      {
          list.add(Sample_List[i]);
      }
  
      final StableArrayAdapter adapter = new StableArrayAdapter(this, R.layout.list_item, list);
      lv.setAdapter(adapter);
      lv.setOnItemClickListener(new AdapterView.OnItemClickListener()
      {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id)
          {
              ...
          }
      });
  }
  </code></pre>
  
  <h1>updates:</h1>
  
  <p>I have updated the codes as follows:</p>
  
  <pre><code>    lv.setAdapter(myAdapter);
      lv.setOnItemClickListener(new AdapterView.OnItemClickListener()
      {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id)
          {
              ... 
          }
      });
  }
  
  public class MyCustomArrayAdapter extends ArrayAdapter&lt;String&gt; 
  {
        private final Context context;
        private final String[] values;
  
        public MyCustomArrayAdapter(Context context, String[] values) 
        {
          super(context, R.layout.list_item, values);
          this.context = context;
          this.values = values;
        }
  
        @Override
        public View getView  (int position, View convertView, ViewGroup parent)
        {
            View  view = super.getView(position, convertView, parent);
            if(position&gt;=3&amp;&amp;position&lt;=7)
            {
                view.setBackgroundResource(R.drawable.green_btn);
            }
            else
            {
                view.setBackgroundResource(R.drawable.white_btn);
            }  
            return view;
        }
  } 
  </code></pre>
  
  <h2>Question:</h2>
  
  <p>I have researched a lot on the web but I still cannot figure out how to implement that <code>getView</code>... in this way how could the above be changed such that for example, background row 3 to 7 to be set in red?</p>
  
  <p>Implemented the updated codes, the listview cannot expand properly to show each item, only item's border can be shown (the green button has some black border), possibly because not linking the list.</p>
  
  <p>How could I connect the list with the MyCustomArrayAdapter?</p>