title: Setting backgrounds of specific listview items by default
body: <p>In my fragment I've been able control the backgrounds of my list item based on the clicking of an item in the list so for example if item 0 is clicked then its background is set to yellow and the backgrounds of the other list items are set GRAY. </p>
  
  <p>I do all this in the onitemclicklistener and it works as expected. See code below:</p>
  
  <pre><code>    lvCodeType.setOnItemClickListener(new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; arg0, View view, int position, long id) {
              //lvCodeType.getChildAt(position).setBackgroundColor(Color.parseColor("#FFCC00"));
  
              //lvCodeType.getChildAt(0).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_rollover);
  
              if(position == 0) {
                  desiredCodeType = "ABCD";
  
                  lvCodeType.getChildAt(position).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_rollover);
  
                  lvCodeType.getChildAt(1).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_default);
                  lvCodeType.getChildAt(2).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_default);
                  lvCodeType.getChildAt(3).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_default);
              } else if(position == 1) {
                  desiredCodeType = "EFGH";
  
                  lvCodeType.getChildAt(0).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_default);
  
                  lvCodeType.getChildAt(1).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_rollover);
  
                  lvCodeType.getChildAt(2).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_default);
                  lvCodeType.getChildAt(3).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_default);
              } else if(position == 2) {
                  desiredCodeType = "AGSOPA";
  
                  lvCodeType.getChildAt(0).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_default);
                  lvCodeType.getChildAt(1).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_default);
  
                  lvCodeType.getChildAt(2).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_rollover);
  
                  lvCodeType.getChildAt(3).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_default);                      
              } else if(position == 3) {
                  desiredCodeType = "MNOP";
  
                  lvCodeType.getChildAt(0).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_default);
                  lvCodeType.getChildAt(1).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_default);
                  lvCodeType.getChildAt(2).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_default);
  
                  lvCodeType.getChildAt(3).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_rollover); 
              } else {
                  desiredCodeType = "";
  
                  lvCodeType.getChildAt(0).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_default);
                  lvCodeType.getChildAt(1).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_default);
                  lvCodeType.getChildAt(2).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_default);
                  lvCodeType.getChildAt(3).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_default);
              }
          }
      });
  </code></pre>
  
  <p>Now I would like on the first time of loading this list before the user engages any of the list items I want to set the background of a specific list item so for example when the list loads up for the first time the background color of item 0 should be YELLOW with the background colors of the other items being GRAY.</p>
  
  <p>I tried the following code in my fragment but outside the listview's onitemclicklistener after setting the list adapter but it failed:
                  lvCodeType.getChildAt(0).setBackgroundResource(R.drawable.bgnd_lv_code_type_item_default);</p>
  
  <p>Any ideas how I could go about this.</p>
  
  <p>Below is my list code in my fragment:</p>
  
  <pre><code>// Inflate and customise code type listview
  lvCodeType = (ListView) rlMain.findViewById(R.id.lv_codetype);
  lvCodeType.setDividerHeight(2);
  lvCodeType.setBackgroundResource(R.drawable.bgnd_lv_code_type);
  
  lvCodeTypeData = new ArrayList&lt;LVCodeTypeDrawer&gt;();
  lvCodeTypeData.add(new LVCodeTypeDrawer("ABCD"));
  lvCodeTypeData.add(new LVCodeTypeDrawer("EFGH"));
  lvCodeTypeData.add(new LVCodeTypeDrawer("IJKL"));
  lvCodeTypeData.add(new LVCodeTypeDrawer("MNOP"));
  
  lvCodeTypeAdapter = new LVCodeTypeAdapter(((MainActivity) getActivity()), 
                                              lvCodeType, 
                                              R.layout.lv_layout_code_type, 
                                              lvCodeTypeData, 
                                              officialRegularFont, 
                                              officialBoldFont);
  
  lvCodeType.setAdapter(lvCodeTypeAdapter);
  </code></pre>
  
  <p>Below is my list adapter code:</p>
  
  <pre><code>public class LVCodeTypeAdapter extends ArrayAdapter&lt;LVCodeTypeDrawer&gt; {
  
      public static String TAG = "LVCodeTypeAdapter";
      Context context;
      List&lt;LVCodeTypeDrawer&gt; drawerItemList;
      int layoutID;
      public Typeface officialBoldFont, officialRegularFont;
      public ListView lvCodeType;
  
      public LVCodeTypeAdapter(Context context, ListView _lvCodeType, int _layoutResourceID, List&lt;LVCodeTypeDrawer&gt; listItems, 
              Typeface _officialRegularFont, Typeface _officialBoldFont) {
  
          super(context, _layoutResourceID, listItems);
  
          this.context = context;
          this.lvCodeType = _lvCodeType;
          this.layoutID = _layoutResourceID;
          this.drawerItemList = listItems;
          this.officialBoldFont =  _officialBoldFont;
          this.officialRegularFont = _officialRegularFont;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
  
          final int _position = position;
  
          LVCodeTypeDrawerItemHolder lvCodeTypeDrawerItemHolder;
  
          View view = convertView;
  
          if (view == null) {
              LayoutInflater inflater = ((Activity) context).getLayoutInflater();
  
              lvCodeTypeDrawerItemHolder = new LVCodeTypeDrawerItemHolder();
  
              view = inflater.inflate(layoutID, parent, false);
  
              lvCodeTypeDrawerItemHolder.itemName = (TextView) view.findViewById(R.id.tv_codetype);
  
              view.setTag(lvCodeTypeDrawerItemHolder);
          } else {
              lvCodeTypeDrawerItemHolder = (LVCodeTypeDrawerItemHolder) view.getTag();
          }
  
          LVCodeTypeDrawer dItem = (LVCodeTypeDrawer) this.drawerItemList.get(_position);
  
          lvCodeTypeDrawerItemHolder.itemName.setText(dItem.getCodeTypeValue());
          lvCodeTypeDrawerItemHolder.itemName.setTypeface(officialBoldFont);
          lvCodeTypeDrawerItemHolder.itemName.setTextSize(14.5f);
          lvCodeTypeDrawerItemHolder.itemName.setTextColor(Color.BLACK);
  
          return view;
      }
  
      private static class LVCodeTypeDrawerItemHolder {
          TextView itemName;
      }
  
  }
  </code></pre>
  
  <p>Thanks.</p>