我知道这个问题被问了很多次,但解决方案对我不起作用。我的TextView
和ImageView
无法点击。
爪哇:
public class temples extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_temples);
ImageView img_view = (ImageView) findViewById(R.id.img1);
img_view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(temples.this, kaal_bhairav_info.class));
}
});
}
}
XML:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_temples" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/img1"
android:layout_width="match_parent"
android:layout_height="200dp"
android:paddingTop="100dp"
android:src="@mipmap/kaal_bhairav"
android:clickable="true"/>
</RelativeLayout>
My logcat is not showing any error but nothing happens when image is clicked.
Same case with `TextView` also.
如果我没有设置onClickListener
并编写方法(也在xml中设置android:onclick)
然后得到错误:
java.lang.IllegalStateException:找不到方法执行 动作(View)在父级或祖先语境中为android:onClick 在视图类上定义的属性 带有id&#39; text_view&#39;
的android.support.v7.widget.AppCompatTextView
我正在使用android studio并在棒棒糖上进行测试。我被卡住了。请帮忙。