how can I show selection of an image in grid view at once

后端 未结 3 578
慢半拍i
慢半拍i 2021-01-07 14:41

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

3条回答
  •  离开以前
    2021-01-07 14:47

    In your code you forgot to unselect all images except the current selected image. only you have done is setting background for selected image. you need to set unseleted images for others aswell

    *Step-1*initialize selected position as -1 in GridAdapter class

    int checked=0;
    int selectedPosition = -1; 
    

    *Step-2*rewrite your onclick method as given below

    @Override
        public void onClick(View v) {
             Log.i("Clicked", "Tag###########");
             //img_select.setVisibility(View.INVISIBLE);
             img_select.setFocusable(true);
             img_select.setEnabled(true);
    
    
            if(checked==0)
            {
                selectedPosition = position;
    
            }
            for(int i = 0; i

提交回复
热议问题