title: Android: How to convert drawable to int?
body: <p>I get the icon of some installed applications using this code:</p>
  
  <pre><code>Drawable icon = getPackageManager().getApplicationIcon("com.example.example");
  imageView.setImageDrawable(icon);
  </code></pre>
  
  <p>then I would like to add this image to a gridview formed by some image in res. i don't want to change the adapter used with my gridview.I use for each item an icon and image saved in two Arraylist. </p>
  
  <pre><code>ArrayList&lt;String&gt; listCountry = new ArrayList&lt;String&gt;();
   ArrayList&lt;Integer&gt; listFlag = new ArrayList&lt;Integer&gt;(); 
  </code></pre>
  
  <p>I add element to my listFlag like that: <code>listFlag.add(R.drawable.ppt);</code></p>
  
  <p>So how can I convert the Drawble to int to add it to <code>listFlag</code>? my adapter to view the item of my gridview is given by the code below:</p>
  
  <pre><code>public  class GridviewAdapter extends BaseAdapter
  {
      private ArrayList&lt;String&gt; listCountry = new ArrayList&lt;String&gt;();
      private ArrayList&lt;Integer&gt; listFlag = new ArrayList&lt;Integer&gt;();
      private Activity activity;
      private Context context;
  
  
      public GridviewAdapter( ) {
           super();
                }
  
      public GridviewAdapter(Activity activity, ArrayList&lt;String&gt; listC, ArrayList&lt;Integer&gt; listF) {
          super();
          this.listCountry.clear();
          this.listFlag.clear();
          //this.notifyDataSetChanged();
          this.listCountry.addAll(listC);
          this.listFlag.addAll(listF);
          this.activity = activity;
          this.context = activity.getApplicationContext();
        this.notifyDataSetChanged();}
  
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          return listCountry.size();
      }
  
      @Override
      public String getItem(int position) {
          // TODO Auto-generated method stub
          return listCountry.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          // TODO Auto-generated method stub
          return 0;
      }
  
      public static class ViewHolder
      {
          public ImageView imgViewFlag;
          public TextView txtViewTitle;
          public TextView txtViewDescription;
      }
  
      public void setFile(ArrayList&lt;String&gt; listC, ArrayList&lt;Integer&gt; listF) {
          listFlag.clear();
          listCountry.clear();
           listCountry.addAll(listC);
          listFlag.addAll(listF);
          notifyDataSetChanged();
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          // TODO Auto-generated method stub
          ViewHolder view;
          LayoutInflater inflator = activity.getLayoutInflater();
  
          if(convertView==null)
          {
              view = new ViewHolder();
              convertView = inflator.inflate(R.layout.gridview_row, null);
  
              view.txtViewTitle = (TextView) convertView.findViewById(R.id.textView1);
              view.imgViewFlag = (ImageView) convertView.findViewById(R.id.imageView1);
              view.txtViewDescription = (TextView) convertView.findViewById(R.id.textView2);
  
              convertView.setTag(view);
  
              convertView.setLayoutParams(new GridView.LayoutParams((int) context.getResources().getDimension(R.dimen.r_width), (int) context.getResources().getDimension(R.dimen.r_height)));
          }
          else
          {
              view = (ViewHolder) convertView.getTag();
          }
  
          view.txtViewTitle.setText(listCountry.get(position));
          view.txtViewTitle.setSelected(true);
          view.txtViewDescription.setText(SessionChoose.DESCRIPTION.get(position));
           view.txtViewDescription.setSelected(true);
          view.imgViewFlag.setImageResource(listFlag.get(position));
  
  
          return convertView;
      }
  }
  </code></pre>