title: Set a drawable as background programmatically
body: <p><strong>EDIT: Sorry I realise from your comment my question was not clear enough. I will post a new one. Sorry for this and thanks for your answers</strong></p>
  
  <p>I am populating a ListView from a Json file.</p>
  
  <p>With my <strong>listadapter</strong>, I can easily assign appropriate json data to each row of my list. That works well for text, for example: </p>
  
  <pre><code>TextView tv = (TextView)ll.findViewById(R.id.descView);   
  tv.setText(i.desc);
  </code></pre>
  
  <p>With the above code, every row will be correctly populated by the good json data.</p>
  
  <p>However, I don't manage to do the same thing for an image. I have tried to set the right image from my json data using this:</p>
  
  <pre><code>ImageView iv = (ImageView)ll.findViewById(R.id.imgView);           
  iv.setBackgroundDrawable(context.getResources().getDrawable(i.img));
  </code></pre>
  
  <p>I guess I am doing something wrong with the type of my parameters: "setBackgroundDrawable" requires a drawable parameter.
  "getDrawable" requires an int.
  I have set the type of my field img to int, but that doesn't work.</p>
  
  <p>Any idea why?</p>
  
  <p>My <strong>list adapter</strong>:</p>
  
  <pre><code>public class adapter extends ArrayAdapter&lt;ListItems&gt; {
  
  int resource;
  String response;
  Context context;
  
  //Initialize adapter
  public ListItemsAdapter(Context context, int resource, List&lt;ListItems&gt; items) {
      super(context, resource, items);
      this.resource=resource; 
  }     
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent)
  {
  
      //Get the current object
      ListItems i = getItem(position);
  
      //Inflate the view
      if(convertView==null)
      {
          ll = new LinearLayout(getContext());
          String inflater = Context.LAYOUT_INFLATER_SERVICE;
          LayoutInflater li;
          li = (LayoutInflater)getContext().getSystemService(inflater);
          li.inflate(resource, ll, true);
      }
      else
      {
          ll = (LinearLayout) convertView;
      }
  
      //For the message
      TextView tv = (TextView)ll.findViewById(R.id.descView);
      tv.setText(i.desc);
  
  // For the Img
      ImageView iv = (ImageView)ll.findViewById(R.id.imgView);
      iv.setBackgroundDrawable(context.getResources().getDrawable(i.img));
  
      return ll;
  }
  </code></pre>
  
  <p>my <strong>item class</strong>:</p>
  
  <pre><code>    public class ListItems{
  int id;
  int img;    
  String desc;}
  </code></pre>
  
  <p>And a sample of my json file:</p>
  
  <pre><code>    [{"id":10001,"img":e1,"desc":"desc1"},
      {"id":10002,"img":e2,"desc":"desc2"},
      {"id":10003,"img":e3,"desc":"desc3"}]
  </code></pre>