开发者社区> 问答> 正文

GridView标签中添加button Adapter配置onclick无效 :报错

public class GridViewVideoAdapter extends BaseAdapter{
private Context context; 


     private Integer[] imgs = { 
             R.drawable.huifang,R.drawable.shang,R.drawable.shishi,
             R.drawable.zuo,R.drawable.play,R.drawable.you,
             R.drawable.liebiao,R.drawable.xia
     }; 
     public GridViewVideoAdapter(Context context){ 
         this.context = context; 
     } 
     public int getCount() { 
         return imgs.length; 
     } 


     public Object getItem(int item) { 
         return item; 
     } 


     public long getItemId(int id) { 
         return id; 
     } 
      


     public View getView(int position, View convertView, ViewGroup parent) { 
          ImageView imageView; 
             if (convertView == null) { 
                 imageView = new ImageView(context); 
                 imageView.setLayoutParams(new GridView.LayoutParams(110, 110));
                 imageView.setAdjustViewBounds(false);
                 imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                 imageView.setPadding(5, 5, 5, 5);      
             }  
             else { 
                 imageView = (ImageView) convertView; 
             } 
             imageView.setImageResource(imgs[position]);
             
             imageView.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
Log.e("imageview", arg0.toString());

}
});
             
             return imageView; 
     } 

}



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:android1="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >


    <LinearLayout
        android1:layout_width="match_parent"
        android1:layout_height="wrap_content"
        android1:layout_weight="0.62"
        android1:orientation="vertical" >


        <VideoView
            android1:id="@+id/video_view"
            android1:layout_width="match_parent"
            android1:layout_height="340dp" />


        <GridView
            android:id="@+id/gridview1"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:background="#FFeff1ef"
            android:gravity="center"
            android:horizontalSpacing="10dp"
            android:numColumns="3"
            android:verticalSpacing="10dp" />
    </LinearLayout>


</LinearLayout>

展开
收起
kun坤 2020-06-20 11:38:02 1100 0
1 条回答
写回答
取消 提交回答
  • 不知道加载监听的正确方法

    2020-06-20 11:38:13
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载