Android之BaseQuickAdapter.setOnItemChildClickListener点击死人也没反应的原因

1 问题

用BaseQuickAdapter设置子view点击事件

            unInstalledAdapter!!.setOnItemChildClickListener(object: BaseQuickAdapter.OnItemChildClickListener {
                override fun onItemChildClick(adapter: BaseQuickAdapter<*, *>?, view: View?, position: Int) {
                    var info =  adapter?.getItem(position)
                    Log.i(TAG, "unInstalledAdapter info is:" + info.toString())
                    when(view?.id) {
                        R.id.installButton -> {Log.i(TAG, "unInstalledAdapter R.id.installButto has happen") }
                        R.id.deleteButton -> {Log.i(TAG, "unInstalledAdapter R.id.deleteButton has happen") }
                    }
                }
            })

死人也没反应

 

 

 

2 解决办法

在适配器里面要记得注册子view的监听事件

helper.addOnClickListener(R.id.installButton);
    @Override
    protect
chen.yu CSDN认证博客专家 博客排名前200
深信服三年半工作经验,目前就职游戏厂商,希望能和大家交流和学习,
微信公众号:编程入门到秃头 或扫描下面二维码

零基础入门进阶人工智能(链接)


已标记关键词 清除标记
Activity类: private String[] mStrings2={"Title 01","Title 02"}; private String[] mStrings = {"Link to the image1", "Link to the image2"}; MyAdapter adapter; mainList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { adapter=new LazyAdapter(this, mStrings, mStrings2); subList.setAdapter(adapternew); } }); MyAdapter class (MyAdapter.java) private Activity activity; private String[] data; private String[] data2; private static LayoutInflater inflater=null; public ImageLoader imageLoader; //Constructor public LazyAdapter(Activity a, String[] d, String[] mStrings2) { activity = a; data=d; data2=mStrings2; inflater = LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); imageLoader=new ImageLoader(activity.getApplicationContext()); } 当我点击第一个 List Item,我想把元素加载到第二个数组中。但是当执行程序后,获得NullPointerException异常。就是说ListView中OnItemClickListener事件不能执行。大家能指导下哪出错了吗? 12-04 14:21:42.499: E/AndroidRuntime(1429): java.lang.NullPointerException 12-04 14:21:42.499: E/AndroidRuntime(1429): at com.java.hotelapp.Item_List$1.onItemClick(Item_List.java:106) 12-04 14:21:42.499: E/AndroidRuntime(1429): at android.widget.AdapterView.performItemClick(AdapterView.java:282) 12-04 14:21:42.499: E/AndroidRuntime(1429): at android.widget.AbsListView.performItemClick(AbsListView.java:1037) 12-04 14:21:42.499: E/AndroidRuntime(1429): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2449) 12-04 14:21:42.499: E/AndroidRuntime(1429): at android.widget.AbsListView$1.run(AbsListView.java:3073) 12-04 14:21:42.499: E/AndroidRuntime(1429): at android.os.Handler.handleCallback(Handler.java:587) 12-04 14:21:42.499: E/AndroidRuntime(1429): at android.os.Handler.dispatchMessage(Handler.java:92) 12-04 14:21:42.499: E/AndroidRuntime(1429): at android.os.Looper.loop(Looper.java:132) 12-04 14:21:42.499: E/AndroidRuntime(1429): at android.app.ActivityThread.main(ActivityThread.java:4123) 12-04 14:21:42.499: E/AndroidRuntime(1429): at java.lang.reflect.Method.invokeNative(Native Method) 12-04 14:21:42.499: E/AndroidRuntime(1429): at java.lang.reflect.Method.invoke(Method.java:491) 12-04 14:21:42.499: E/AndroidRuntime(1429): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) 12-04 14:21:42.499: E/AndroidRuntime(1429): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 12-04 14:21:42.499: E/AndroidRuntime(1429): at dalvik.system.NativeStart.main(Native Method)
©️2020 CSDN 皮肤主题: 猿与汪的秘密 设计师:上身试试 返回首页
实付 19.90元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值