How do you make the press of an imageview change another imageviews background image?
My code keeps giving me a null pointer exception error but I dont know why.
The java code
ImageView imageview2 = (ImageView) findViewById(R.id.imageview2);
public void onclickname(View v) {
imageview2.setImageResource(R.drawable.example);}
The clickable imageview
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:clickable="true"
android:src="@drawable/example"
android:id="@+id/imageview1"
android:onClick="onclickname"/>
The imageview whos background image i want to change.
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/red"
android:id="@+id/imageview2"/>