I’m a newbie developer and I am currently working on an app in which part of the functionality allows users to capture an image, store it in the app’s file system, and store
In my application I want to store profile picture of user in SQLite database So I have added one String Column for Storing Path of Image,image will be selected from Gallery
//Executed When user Click on image for selecting profile from Gallery
ImageView profileperson = (ImageView) findViewById(R.id.profileperson);
profileperson.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, 1);
}
});
String path;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1 && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] fillPath = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, fillPath, null, null, null);
assert cursor != null;
cursor.moveToFirst();
path = cursor.getString(cursor.getColumnIndex(fillPath[0]));
cursor.close();
profileperson.setImageBitmap(BitmapFactory.decodeFile(path));
}
}
Then in for displaying I have fetch path of image using Cursor
String employeeimage;
...
employeeimage = cursor.getString(cursor.getColumnIndex("employeeimage")); //employeeimage is column name
Now I have display all data in RecyclerView so I have use Adapter for binding data.
List<Data> list = Collections.emptyList();
...
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
/*
* get items from list of particular position and set into respective textview
* */
String path=list.get(position).employeeImage;
Picasso.with(context).load(new File(path)).into(holder.imageViewPerson);
}