Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need custom <code>ListAdapter</code> to add your image. One way is to subclass the <code>ArrayAdapter</code> (used by default by the <code>AlertDialog</code>). Here is an example:</p> <pre><code>final Item[] items = { new Item("Email", android.R.drawable.ic_menu_add), new Item("Facebook", android.R.drawable.ic_menu_delete), new Item("...", 0),//no icon for this one }; ListAdapter adapter = new ArrayAdapter&lt;Item&gt;( this, android.R.layout.select_dialog_item, android.R.id.text1, items){ public View getView(int position, View convertView, ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView)v.findViewById(android.R.id.text1); //Put the image on the TextView tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0); //Add margin between image and text (support various screen densities) int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } }; new AlertDialog.Builder(this) .setTitle("Share Appliction") .setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { //... } }).show(); </code></pre> <p>Here is the Item class</p> <pre><code>public static class Item{ public final String text; public final int icon; public Item(String text, Integer icon) { this.text = text; this.icon = icon; } @Override public String toString() { return text; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload