GridView on item click listener

前端 未结 2 854
日久生厌
日久生厌 2021-01-16 13:58
        gridView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView parent, View v,
                int position         


        
相关标签:
2条回答
  • 2021-01-16 14:13

    Here's the cleanest way to do it: call performItemClick() on the GridView from within each button's click listener in your Adapter. That way you can still use the GridView's onItemClickListener like normal.

    // in your ListAdapter
    @Override
    public View getView(final int position, final View convertView, final ViewGroup parent) {
    
        // set btn to be your item's view
        ...
    
        btn.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View v) {
                ((GridView) parent).performItemClick(v, position, 0);
            }
        });
    }
    

    From http://www.migapro.com/click-events-listview-gridview/

    0 讨论(0)
  • 2021-01-16 14:16

    does the gridView have a custom layout ?

    if yes, go to the custom layout xml file and change these attributes

    android:clickable="false"
    android:focusable="false"
    
    0 讨论(0)
提交回复
热议问题