Olimjon
Olimjon

Reputation: 25

Load file from Sample File Directory named "images"

I have this simple structure

image

Now I should load 11.png to ImageView from URI. How do I do this?

imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageURI(Uri.fromFile(new File("What should be here???")));

Upvotes: 1

Views: 65

Answers (1)

Tomin B Azhakathu
Tomin B Azhakathu

Reputation: 2686

I think you Are New To Android?

Its Better To move the Image File to Drawable Folder and and Set Image View From the Drawable. You Can Use BatchDrawableImport Plugin in Android Studio to Import multiple Drawable Files

imageView = (ImageView)findViewById(R.id.imageView);
imageView.setImageResource(R.drawable.yourImageName);

Or Move the File to Assets Folder and Using Assets Manager You Can Achieve the Solution

    AssetManager manager = getAssets();

    // Read a Bitmap from Assets
    try {
        InputStream open = manager.open("icon.png");
        Bitmap bitmap = BitmapFactory.decodeStream(open);
        ImageView view = (ImageView) findViewById(R.id.ImageView01);
        view.setImageBitmap(bitmap);
    } catch (IOException e) {
        e.printStackTrace();
    } 

Upvotes: 1

Related Questions