How to add gridview setOnItemClickListener

后端 未结 6 1324
难免孤独
难免孤独 2020-12-16 14:42

I have a GridView with 81 buttons on it. I want to add clicklistener to this gridview but it is not available. I have added the OnItemClickListener but it is not working and

6条回答
  •  清酒与你
    2020-12-16 15:09

    I am suggesting you to add click listener in getview method rather than adding in activity class. try this code

    @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 OnClickListener() {
    
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
                //Do your task here
            }
        });
        return gridView;
    }
    

提交回复
热议问题