I am trying to develop the functionality, where the user can click on the image to select an image to upload on the same view being clicked. I define the ImageView as follows
<ImageView
style = "@style/DefaultButton"
android:id="@+id/choose_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp"
android:clickable="True"
android:adjustViewBounds="true"
android:onClick="chooseImg"
android:contentDescription="@string/description_logo"
android:src="@drawable/user2" />
the method chooseImg is as follows
public void chooseImg(View view){
Toast.makeText(this, "Choose Image from Gallery", Toast.LENGTH_SHORT).show();
Intent chimg = new Intent(Intent.ACTION_GET_CONTENT);
chimg.setType("image/*");
startActivityForResult(chimg,CHOOSE_IMAGE_REQUEST_CODE);
}
The method is not being called. please help me out to know the reason. Thanks :).
The method that gets called by
android:onClickmust match the method that you want to be executed… But your method on onClick iscaptureImgand your method name in activity ischooseImg. Change these to the same method name and it should solve your problem. Also see my comment.