Android可点击层
我已经将linearlayer设置为可点击,并希望它能像按钮一样启动新的活动。然而,我得到了错误。下面是.xml文件的一部分Android可点击层,android,button,layer,clickable,Android,Button,Layer,Clickable,我已经将linearlayer设置为可点击,并希望它能像按钮一样启动新的活动。然而,我得到了错误。下面是.xml文件的一部分 <LinearLayout android:id="@+id/llproduct1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation=
<LinearLayout
android:id="@+id/llproduct1"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:clickable="true">
<ImageView .... />
<TextView .... />
</LinearLayout>
出了什么问题
Button bProduct1 = (Button) findViewById(R.id.llproduct1);
不能将线性布局强制转换为按钮。但你可以做到:
LinearLayout bProduct1 = (LinearLayout) findViewById(R.id.llproduct1);
bProduct1.setOnClickListener(...)
BPProduct1=Button findViewByIdR.id.llproduct1中的类转换错误 “llproduct1”是线性布局!!没有按钮。 因此,java代码导致ClassCastException onClick方法在视图类中声明。 LinearLayout和Button都继承了视图类 那么,为什么不修复下面的代码呢
你的错误是什么?谢谢!!但我想我还有一个错误,仍然有错误。谢谢但我想我还有一个错误,仍然有错误。
LinearLayout bProduct1 = (LinearLayout) findViewById(R.id.llproduct1);
bProduct1.setOnClickListener(...)
View bProduct1 = findViewById(R.id.llproduct1);
bProduct1.setOnClickListener(......);