Search code examples
androidandroid-layoutgridviewandroid-gridviewandroid-gridlayout

How to Change the click listener position on grid view images?


enter image description here

I am using the below material design for my android app, in my app i also include the navigation drawer on new version 23 , in this grid view each image i click this to open new activity page,.

But in my app, i will not be opened , if i clicked left side above part section only the respective activity will be opened ,

Shall i know how to change the position for the click on my grid view image correctly ,

Please help me to solve my issue ,

Please check the image for clarification !!!

Thank you in advance


Solution

  • You can add ClickListener inside adapter

      @Override
        public View getView(int position, View convertView, ViewGroup parent) {
    
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
        View gridView;
    
        gridView =new View(mContext);
    
        gridView = inflater.inflate(R.layout.gridview_members, null);
    
        Button city = (Button) gridView.findViewById(R.id.city);
    
                    city.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
    
        //Toast here
    
            }});
    
        return gridView;
    }
    

    Hopefully above code will help you