Dipti Agravat Dipti Agravat - 5 months ago 80
Android Question

How to set Image on CircleImageView when i clicked it?

Here i want to create one circleimageview and set image on it from gallarIn which i create one circleimageview
how to set images from gallary in circleimage view?

My Xml file

<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profile_image"
android:layout_width="76dp"
android:layout_height="76dp"
android:src="@drawable/profile"
</de.hdodenhof.circleimageview.CircleImageView>


Here i created object of circeimageview
and pass intent for choose image from gallary

In Java File

profileImage =(de.hdodenhof.circleimageview.CircleImageView)findViewById(R.id.profile_image);
profileImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Toast.makeText(getApplicationContext(), "Profile Pic", Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);//
startActivityForResult(Intent.createChooser(intent, "Select File"),SELECT_FILE);
}
});

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
if (requestCode == SELECT_FILE)
onSelectFromGalleryResult(data);
}
}
@SuppressWarnings("deprecation")
private void onSelectFromGalleryResult(Intent data) {
Bitmap bm=null;
if (data != null) {
try {
bm = MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), data.getData());
} catch (IOException e) {
e.printStackTrace();
}
}
profileImage.setImageBitmap(bm);
}


Help me to solve this.

want to create profile picture with circle image view.?

i found so many tutorial but there have no onclick event

Answer

Hey i found the answer finally

<de.hdodenhof.circleimageview.CircleImageView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/profile_image"
    android:layout_width="76dp"
    android:layout_height="76dp"
    android:src="@drawable/profile"
    android:clickable="true"
    android:layout_marginLeft="24dp"
    android:layout_centerVertical="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginStart="24dp">

</de.hdodenhof.circleimageview.CircleImageView>

Here,

android:Clickable="true"

Solve my problem

Thanks to all