简体   繁体   English

如何将此图片设置为Android活动

[英]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. 我正在Android上使用Async下载文件,现在我希望此文件在活动中显示。 How can I do this inside onSucess method? 如何在onSucess方法中执行此操作? 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. 您可以将ImageView放在XML布局中,也可以动态创建一个ImageView并将其添加到活动中。 Then simply set the image for the ImageView to display. 然后只需设置图像以显示ImageView。

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);
         }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Android Studio中的活动中创建移动的背景图像 - How can I create a moving background image in an activity in android studio 如何在一个活动中将图像从ImageView发送到另一个活动中的ImageButton。 Android Studio - How can I send an image from an ImageView in one activity to an ImageButton in another activity. Android Studio 我如何设置 GIF 图像全屏 Android - How can i set the GIF image fullscreen Android 如何显示Android Java中设置的图像? - How can I show image set in android java? 我如何在onpostexecute Android上更改活动 - How i can to change activity on onpostexecute Android 如何在Android中以编程方式设置活动的父活动? - How to set parent activity of an activity programmatically in android? 如何将活动设置为仅通过TapBarMenu分配的按钮单击变量,其中String为Web,图像项为ImageId? - How can I set an activity to a button click variable that is only assigned via TapBarMenu with String as web and an image item as ImageId? 如何为Android设置背景图片? - How do I set a background image for Android? 如何为活动中的滚动视图设置最大高度? - How can I set a maximum height for a Scroll View in an Activity? 如何为NavigationDrawer活动的不同片段设置不同的onBackPressed()? - How can i set different onBackPressed() for different fragment of a NavigationDrawer Activity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM