Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try this .. in your activity</p> <pre><code>public static HashMap&lt;String, Integer&gt; ThemeId = new HashMap&lt;String, Integer&gt;(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ..... ThemeId.clear(); ThemeId.put("apple", R.drawable.apple); ThemeId.put("ant", R.drawable.ant); ThemeId.put("aeroplane", R.drawable.aeroplane); ThemeId.put("alligator", R.drawable.alligator); ThemeId.put("arrow", R.drawable.arrow); ThemeId.put("arm", R.drawable.arm); } </code></pre> <p>//in base adapter </p> <pre><code> import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; public class AlphabetAdapter extends BaseAdapter { private Context context; private final String[] alphabets; public AlphabetAdapter(Context context, String[] alphabets) { this.context = context; this.alphabets = alphabets; } public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View gridView; if (convertView == null) { gridView = new View(context); gridView = inflater.inflate(R.layout.custom_six_alphabets, null); TextView textView = (TextView) gridView.findViewById(R.id.label); textView.setText(alphabets[position]); ImageView flag = (ImageView) gridView.findViewById(R.id.flag); String mobile = alphabets[position]; flag.setImageResource(YourActivity.ThemeId.get(mobile)); } else { gridView = (View) convertView; } return gridView; } @Override public int getCount() { return alphabets.length; } @Override public String getItem(int position) { return alphabets[position]; } @Override public long getItemId(int position) { return position; } } </code></pre>
 

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