List of usage examples for android.widget SimpleAdapter SimpleAdapter
public SimpleAdapter(Context context, List<? extends Map<String, ?>> data, @LayoutRes int resource, String[] from, @IdRes int[] to)
From source file:com.android.mms.ui.ComposeMessageActivity.java
private void showSmileyDialog() { if (mSmileyDialog == null) { int[] icons = SmileyParser.DEFAULT_SMILEY_RES_IDS; String[] names = getResources().getStringArray(SmileyParser.DEFAULT_SMILEY_NAMES); final String[] texts = getResources().getStringArray(SmileyParser.DEFAULT_SMILEY_TEXTS); final int N = names.length; List<Map<String, ?>> entries = new ArrayList<Map<String, ?>>(); for (int i = 0; i < N; i++) { // We might have different ASCII for the same icon, skip it if // the icon is already added. boolean added = false; for (int j = 0; j < i; j++) { if (icons[i] == icons[j]) { added = true;//from ww w. j av a 2 s .co m break; } } if (!added) { HashMap<String, Object> entry = new HashMap<String, Object>(); entry.put("icon", icons[i]); entry.put("name", names[i]); entry.put("text", texts[i]); entries.add(entry); } } final SimpleAdapter a = new SimpleAdapter(this, entries, R.layout.smiley_menu_item, new String[] { "icon", "name", "text" }, new int[] { R.id.smiley_icon, R.id.smiley_name, R.id.smiley_text }); SimpleAdapter.ViewBinder viewBinder = new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Object data, String textRepresentation) { if (view instanceof ImageView) { Drawable img = getResources().getDrawable((Integer) data); ((ImageView) view).setImageDrawable(img); return true; } return false; } }; a.setViewBinder(viewBinder); AlertDialog.Builder b = new AlertDialog.Builder(this); b.setTitle(getString(R.string.menu_insert_smiley)); b.setCancelable(true); b.setAdapter(a, new DialogInterface.OnClickListener() { @Override @SuppressWarnings("unchecked") public final void onClick(DialogInterface dialog, int which) { HashMap<String, Object> item = (HashMap<String, Object>) a.getItem(which); String smiley = (String) item.get("text"); if (mSubjectTextEditor != null && mSubjectTextEditor.hasFocus()) { mSubjectTextEditor.append(smiley); } else { mTextEditor.append(smiley); } dialog.dismiss(); } }); mSmileyDialog = b.create(); } mSmileyDialog.show(); }