简体   繁体   中英

How can I set this image to activity in Android

I'm downloading file using Async on android, Now i want this files to display on activity. How can I do this inside onSucess method? I tried below method but image is not showing!

AsyncHttpClient fileDownload = new AsyncHttpClient();
String[] allowedContentTypes = new String[] { "image/png", "image/jpeg" };
fileDownload.get("http://server.com/file.png", new BinaryHttpResponseHandler(allowedContentTypes)           {
       @Override
       public void onSuccess(byte[] fileData) {
        //Do Something here to view files in activity   
       ImageView img = (ImageView) findViewById (R.id.imageview1);   
}

You can either place an ImageView in your XML layout or create one dynamically and add it to the activity. Then simply set the image for the ImageView to display.

Try this code

AsyncHttpClient fileDownload = new AsyncHttpClient();
String[] allowedContentTypes = new String[] { "image/png", "image/jpeg" };
fileDownload.get("http://server.com/file.png", new BinaryHttpResponseHandler(allowedContentTypes) {
       @Override
       public void onSuccess(byte[] fileData) {
        //Do Something here to view files in activity  
         Bitmap bmp=BitmapFactory.decodeByteArray(fileData,0,fileData.length); 
         ImageView img = (ImageView) findViewById (R.id.imageview1);
         img.setImageBitmap(bmp);
         }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM