1

I am having arraylist string of image urls. On imageclick I want to send selected image URL to another activity.i successfully send the arraylist string url in 2nd activity..but now my point is that how i can display the image from the recieving path.see my code below..thanks in advance.

my 1st activity when i am sending image url to 2nd activity:

 iv_openimage = (ImageView) findViewById(R.id.iv_openimage);
    iv_openimage.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(VarientDetails.this,ImageSwitcher.class);

            intent.putExtra("imageurls", imageurls);
            Log.d("CMH", "images url = " + imageurls);
            startActivity(intent);
        }
    });

and this is my 2nd activity where i can recieve image url.and i want to display my image from the recieving url.

public class ImageSwitcher extends Activity {

ImageView iv_getimage;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.imageswitcher);

    iv_getimage = (ImageView) findViewById(R.id.imageView1);
    ArrayList<String> resultArray = getIntent().getStringArrayListExtra("imageurls");
    Log.d("CMH imgswtchr", "images url = " + resultArray);


}
}

i recieved the image url..now i just want it to display my image from the recieving url.

this is my xml of the 2nd activity:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="142dp"
    android:layout_marginTop="247dp"
     />

</RelativeLayout>
Farhan Shah
  • 2,344
  • 7
  • 28
  • 54

2 Answers2

3

I recommend you to user Picasso for Android developed by Square.

http://square.github.io/picasso/

It gets so easy as this.

public class ImageSwitcher extends Activity {

    ImageView iv_getimage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
       // TODO Auto-generated method stub
       super.onCreate(savedInstanceState);
       setContentView(R.layout.imageswitcher);

       iv_getimage = (ImageView) findViewById(R.id.imageView1);
       ArrayList<String> resultArray = getIntent().getStringArrayListExtra("imageurls");
       Log.d("CMH imgswtchr", "images url = " + resultArray);

       Picasso.with(getBaseContext()).load(resultArray.get(0)).into(iv_getimage);

   } 
}

You just have to download the .jar file and add it to your libs folder inside your project

UPDATE for the request on the comment:

Android: How to handle right to left swipe gestures

Hope it helps! :)

Community
  • 1
  • 1
reixa
  • 6,903
  • 6
  • 49
  • 68
  • Thanks Alot buddy it's work fine.+1 for solving my issue..dear can u please tell me that how i can implement the finger swipe animation in my second activity when i display the images..i mean when the images are display,i can move this images right and left with finger swipes. – Farhan Shah Dec 19 '13 at 12:00
  • @FarhanShah I made an update to my answer with a link to a SO question that talks about what you're wanting to do. It also has a good score so it may be a good answer. – reixa Dec 19 '13 at 12:06
2

For Downloading Images use Async HTTP Client.

I have a suggestion Try to Use AsyncHttpclient for getting responses from server no need of this long codes.

http://loopj.com/android-async-http/

                AsyncHttpClient client = new AsyncHttpClient();
                        String[] allowedContentTypes = new String[] {
                                "image/png", "image/jpeg", "image/jpg" };

                        client.get(GlobalVars.VendorData
                                .getVendorLogo(),
                                new BinaryHttpResponseHandler(
                                        allowedContentTypes) {
                                    @Override
                                    public void onSuccess(
                                            byte[] fileData) {
                                        // Do something with the file
                                        System.out
                                                .println("Image Loaded.. "
                                                        + fileData);

                                        Bitmap bmp = BitmapFactory
                                                .decodeByteArray(
                                                        fileData, 0,
                                                        fileData.length);

                                        vendor_icon.setImageBitmap(bmp);
                                    }

                                    @Override
                                    protected void handleFailureMessage(
                                            Throwable arg0, String arg1) {
                                        // TODO Auto-generated method
                                        // stub
                                        super.handleFailureMessage(
                                                arg0, arg1);
                                        System.out
                                                .println("Image Loaded.. "
                                                        + arg1);
                                    }
                                });

You need to include the jar file also.

Ashwin S Ashok
  • 3,623
  • 2
  • 29
  • 36