【发布时间】:2016-04-08 01:34:02
【问题描述】:
我正在尝试通过单击图像按钮来打开一个新活动。我放置了 imagebutton 并尝试为它创建一个 onclick 方法。该应用程序已经在我尝试找到我的按钮的地方崩溃了。它确实打印了第一个日志,但就是这样。它甚至没有到达 onClick 方法。我对 android 很陌生,所以我几乎没有使用它的经验。
public class Bestellingen extends AppCompatActivity implements AdapterView.OnItemClickListener {
private ArrayList<String> elementen;
private ListView lV;
private MenuAdapter mA;
ImageView image;
Spinner spinner1;
ImageButton imageButtonWinkelmand;
public Bestellingen() {
Log.d("tag","test");
imageButtonWinkelmand = (ImageButton) findViewById(R.id.imageWinkelmand); // here
Log.d("testje","erna");
}
我的 onClick 方法
imageButtonWinkelmand.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("in de onclick","test");
startActivity(new Intent(Bestellingen.this, BestellingenInfo.class));
}
});
我确实在activity_main.xml中做到了
<ImageButton
android:layout_width="80dp"
android:layout_height="70dp"
android:scaleType="fitXY"
android:id="@+id/imageWinkelmand"
android:src="@drawable/winkelmand"
android:layout_marginLeft="10dp"
android:layout_marginTop="-20dp"
android:background="#00000000"
android:contentDescription="winkelmandje"/>
聊天对话结束
【问题讨论】:
-
在这里发布你的日志。
-
在你的 oncreate 部分调用这个
imageButtonWinkelmand = (ImageButton) findViewById(R.id.imageWinkelmand); -
把它放在 onCreate() 工作,谢谢!
标签: android image button crash imagebutton