Note that there are some explanatory texts on larger screens.

plurals
  1. POhow can I show selection of an image in grid view at once
    text
    copied!<p>I have a question that I have a custom grid view in which two images one is the background image and second is the check mark image, when I clicked on one Item of grid view check mark shows which presents selection of image but when we want to select a second item of grid view it also shows check marks on the same image as shown in an below attached image, but I want that only one image can be selected at once, means if one is selected other checkmarks will goes to be hidden. Please suggest me the right result.</p> <p><img src="https://i.stack.imgur.com/UkdO2.png" alt="enter image description here"></p> <p><strong>Code:</strong> <strong>GridAdapter:</strong></p> <pre><code>public class GridAdapter extends BaseAdapter { private Activity activity; private LayoutInflater inflater = null; ArrayList&lt;Integer&gt; items = new ArrayList&lt;Integer&gt;(); int checked=0; public GridAdapter(Activity a, ArrayList&lt;Integer&gt; items) { activity = a; this.items = items; inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public int getCount() { return items.size(); } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(final int position, View convertView, ViewGroup parent) { // View v = convertView; ImageView img; final ImageView img_select; if (convertView == null) { convertView = inflater.inflate(R.layout.grid_items, null); img_select = (ImageView)convertView.findViewById(R.id.check_image); img_select.setTag(position); img = (ImageView)convertView.findViewById(R.id.img_GridItem); img.setTag(position); //img_select = (ImageView)v.findViewById(R.id.itemCheckBox); img.setBackgroundResource(items.get(position)); img.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Log.i("Clicked", "Tag###########"); //img_select.setVisibility(View.INVISIBLE); img_select.setFocusable(true); img_select.setEnabled(true); if(checked==0) { img_select.setBackgroundResource(R.drawable.selectimage); GreetingTextContainer greet = GreetingTextContainer.getSingletonObject(); greet.setPosition(position); checked =1; } else { img_select.setBackgroundResource(0); checked=0; } } }); } return convertView; } } </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