java - OnClick JS 类似事件
问题描述
我是 Android Studio 的新手,我不知道为什么这段代码不起作用。
GridLayout divNum1 = findViewById(R.id.DivNum1);
divNum1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showItemPage(v);
}
});
解决方案
您必须将点击功能添加到布局中。你可以试试这个。
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
tools:context=".MainActivity">
</GridLayout>
推荐阅读
- html - 如何检索与在Django中单击的链接对应的数据
- reactjs - 如何在 react js 中检查材质 ui 主题的类型?(亮或暗)
- android - 如何使用 Glide/Picasso 等库从 Web 加载 Vector Drawable 资源?
- python - 尝试使用 Kafka 和 pyspark 在 postgreSQL 中从 spark 编写流数据帧
- python - python itertools组合消失
- vb6 - 在VB6中使用databse如何将一个表单中的数据显示到另一个表单?
- linux - 如何检查 git commit 中的文件是否是符号链接而无需签出
- c++ - 如何解决 LINK:致命错误 LNK1181:无法打开输入文件 'vtkCommonCore-9.0.lib'
- sql-server - SSRS 中的日期范围参数。将相同的日期值传递给 @StartDate 和 @EndDate 不返回任何数据
- vb.net - 如何使图片框闪烁