Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Refer this tutorial for Custom Grid View</p> <p><a href="http://www.mkyong.com/android/android-gridview-example/" rel="nofollow">http://www.mkyong.com/android/android-gridview-example/</a></p> <pre><code> gridView = (GridView) findViewById(R.id.gridView1); gridView.setAdapter(new ImageAdapter(this, MOBILE_OS)); gridView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) { Toast.makeText( getApplicationContext(), ((TextView) v.findViewById(R.id.grid_item_label)) .getText(), Toast.LENGTH_SHORT).show(); } }); public class ImageAdapter extends BaseAdapter { private Context context; private final String[] mobileValues; public ImageAdapter(Context context, String[] mobileValues) { this.context = context; this.mobileValues = mobileValues; } 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); // get layout from mobile.xml gridView = inflater.inflate(R.layout.mobile, null); // set value into textview TextView textView = (TextView) gridView .findViewById(R.id.grid_item_label); textView.setText(mobileValues[position]); // set image based on selected text ImageView imageView = (ImageView) gridView .findViewById(R.id.grid_item_image); String mobile = mobileValues[position]; if (mobile.equals("Windows")) { imageView.setImageResource(R.drawable.windows_logo); } else if (mobile.equals("iOS")) { imageView.setImageResource(R.drawable.ios_logo); } else if (mobile.equals("Blackberry")) { imageView.setImageResource(R.drawable.blackberry_logo); } else { imageView.setImageResource(R.drawable.android_logo); } } else { gridView = (View) convertView; } return gridView; } @Override public int getCount() { return mobileValues.length; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    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