开发者

Android - How can I load an image to a ImageView?

I want to make a simple image viewing program, that just takes the images from a certain folder, and loads them from it.

I did some coding with less thinking, so I did stumble upon this:

Button btn = (Button) this.findViewById(R.id.but开发者_JS百科tonNext);
        btn.setOnClickListener(new OnClickListener() {

   public void onClick(View v) 
   {
    View rootView = (View)v.getParent();
    ImageView im = (ImageView) rootView.findViewById(R.id.imageView);
    //and here comes the problem...


   }

I have all my images from the folder loaded and have a collection, containg of all their absolute paths. Now, I want my imageView to switch its picture src with one from my collection. But how can I do that ?


Use Bitmaps. After reading the file from the absolute paths, convert to Bitmaps (see BitmapFactory) and apply the Bitmap to the ImageView.


Collections Filled with Absolute Paths? I'd recommend you create an int Array of their Id's (R.drawable.image01) then use the setImageResource(arr[3]) to set it...

But if you have to use the paths...then this page might help...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜