使用来自url的picasso库加载图像

时间:2017-04-27 09:58:16

标签: android url picasso

最初,我从服务器获取图像URL到字符串然后使用Picasso库我试图加载图像
我能够从服务器获取图像URL,如logcat

但图像未在图像视图中加载。当尝试放置直接URL时,它可以工作。

public class MainActivity extends AppCompatActivity {
ImageView im;
Button bm;


String str ;
private static String NAMESPACE = "http://telview360/";
private static String URL = "http://54.179.134.139/viView360Service/WebService.asmx?WSDL";
private static String SOAP_ACTION = "http://telview360/ImageDetails";
private static String METHOD_NAME = "ImageDetails";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.load_image);

    final Thread networkThread = new Thread() {
        @Override
        public void run() {
            try {
                SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelope.setOutputSoapObject(request);

                HttpTransportSE ht = new HttpTransportSE(URL);
                ht.call(SOAP_ACTION, envelope);
                final SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
                str = response.toString();

                Log.d("Webservice", " response " + str);


            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    networkThread.start();


    bm = (Button) findViewById(R.id.btn_load_image);


    bm.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            im = (ImageView) findViewById(R.id.image);
            Picasso.with(getApplicationContext()).load(str).into(im);

        }
    });
  }
}

1 个答案:

答案 0 :(得分:0)

将此添加到您的代码

   final Thread networkThread = new Thread() {
        @Override
        public void run() {
            try {
                SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelope.setOutputSoapObject(request);

                HttpTransportSE ht = new HttpTransportSE(URL);
                ht.call(SOAP_ACTION, envelope);
                final SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
                str = response.toString();

                Log.d("Webservice", " response " + str);


            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    networkThread.start();
    try {
        Thread.currentThread().sleep(100);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

它会起作用