【问题标题】:Why setOnClickListener() did not work for GridView (AdapterView)为什么 setOnClickListener() 不适用于 GridView (AdapterView)
【发布时间】:2014-12-02 18:18:18
【问题描述】:

当我尝试为 GridView (AdapterView) 设置点击监听器时,程序崩溃和 Logcat :“不要为 AdapterView 调用 setOnClickListener”。

添加:为什么机制(Adapterview 无法在点击时调用)这样工作?

【问题讨论】:

  • 改为使用setOnItemClickListener()
  • 问题不清楚,请提供更多信息以及代码..
  • 主啊!请发布您的代码和 log-cat 跟踪。
  • 明确定义,你想要的是整个GridView的点击,还是GridItem的点击?
  • 整个 GridView,以及它是如何工作的

标签: android


【解决方案1】:

尝试使用onItemClick

public abstract void onItemClick (AdapterView<?> parent, View view, int position, long id)

Added in API level 1
Callback method to be invoked when an item in this AdapterView has been clicked.

Implementers can call getItemAtPosition(position) if they need to access the data associated with the selected item.

【讨论】:

    【解决方案2】:

    你应该尝试 setOnItemClickListener 函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-18
      • 2020-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-06
      相关资源
      最近更新 更多