I am trying to open a new activity by clicking on an imagebutton. I placed the imagebutton and tried to make an onclick method for it. The app already crashes on the place where I try to find my button.It does print the first Log but that's it. It doesn't even get to the onClick method. I am very new to android so I have very little experience working with it.
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");
}
My onClick method
imageButtonWinkelmand.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("in de onclick","test");
startActivity(new Intent(Bestellingen.this, BestellingenInfo.class));
}
});
and I did make it in the 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"/>
Chat Conversation End
imageButtonWinkelmand = (ImageButton) findViewById(R.id.imageWinkelmand);