英文:
OnClick JS like event
问题
我刚开始使用Android Studio,不知道为什么这段代码不起作用。
GridLayout divNum1 = findViewById(R.id.DivNum1);
divNum1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showItemPage(v);
}
});
英文:
I'm new to Android Studio, and I don't know why is this code not working.
GridLayout divNum1 = findViewById(R.id.DivNum1);
divNum1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showItemPage(v);
}
});
答案1
得分: 0
你必须向布局中添加点击功能。你可以尝试以下代码。
<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>
英文:
You must add click feature to the layouts. You can try this.
<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>
专注分享java语言的经验与见解,让所有开发者获益!
评论