Android 无法使用简单适配器在listview中显示位图图像数组

Android 无法使用简单适配器在listview中显示位图图像数组,android,magento,android-listview,simpleadapter,Android,Magento,Android Listview,Simpleadapter,我是android编程新手。所以我需要在我面临的问题上得到帮助。 实际上,我正在使用eclipse从android应用程序中的magento获取数据。我使用简单适配器在listview中显示文本和图像。文本数据在listview中完美显示,但我在listview中显示图像时遇到问题。我所做的是显示图像:- MainActivity.javaclass public class MainActivity extends Activity { private static final S

我是android编程新手。所以我需要在我面临的问题上得到帮助。 实际上,我正在使用eclipse从android应用程序中的magento获取数据。我使用简单适配器在listview中显示文本和图像。文本数据在listview中完美显示,但我在listview中显示图像时遇到问题。我所做的是显示图像:- MainActivity.javaclass

public class MainActivity extends Activity {


    private static final String NAMESPACE = "urn:Magento";
    private static final String URL = "url of magento";
    Bitmap bitmap;
    URL imageURL = null;

    ArrayList<Bitmap> bitmapArray = new ArrayList<Bitmap>();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
        TextView tv1 = (TextView) findViewById(R.id.tv);
          ListView lv = (ListView) findViewById(R.id.lv);
          ImageView   image_view = (ImageView)findViewById(R.id.imageview); 
        try {

            SoapSerializationEnvelope env = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);

            env.dotNet = false;
            env.xsd = SoapSerializationEnvelope.XSD;
            env.enc = SoapSerializationEnvelope.ENC;

            SoapObject request = new SoapObject(NAMESPACE, "login");

            request.addProperty("username", "cheker");
            request.addProperty("apiKey", "123456");

            env.setOutputSoapObject(request);

            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,3600000);

            androidHttpTransport.call("", env);
            Object result = env.getResponse();

            Log.d("sessionId", result.toString());

            SoapSerializationEnvelope env1 = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);

            env1.dotNet = false;
            env1.xsd = SoapSerializationEnvelope.XSD;
            env1.enc = SoapSerializationEnvelope.ENC;

            SoapObject request1 = new SoapObject(NAMESPACE, "login");

            request1.addProperty("username", "cheker");
            request1.addProperty("apiKey", "123456");

            env1.setOutputSoapObject(request1);

            HttpTransportSE androidHttpTransport1 = new HttpTransportSE(URL,60000);

            androidHttpTransport1.call("", env1);
            Object result2 = env1.getResponse();

            String sessionId = result.toString();
        request = new SoapObject(NAMESPACE, "catalogProductList");
            request.addProperty("parentCategory","2" );
            request.addProperty("sessionId",sessionId );
            request.addProperty("productId",1 );

            env.setOutputSoapObject(request);
            androidHttpTransport.call("", env);


           Object   result1 = env.getResponse();
         ArrayList<String> ar = new ArrayList<String>();

            for (int i = 0; i <((SoapObject) result1).getPropertyCount(); i++) 
            {
                Object property = ((SoapObject) result1).getProperty(i);
                if (property instanceof SoapObject)
                {
                    SoapObject category_list = (SoapObject) property;
                String   mStringSchoolName = category_list.getProperty("name").toString();
               //  String      mStringSchoolGrade = category_list.getProperty("category_id").toString();
              //   String     mStringSchoolType = category_list.getProperty("parent_id").toString();


                    System.out.println("mStringSchoolName "+mStringSchoolName);
                  //  System.out.println("mStringSchoolGrade "+mStringSchoolGrade);
                  //  System.out.println("mStringSchoolType"+mStringSchoolType);
                    ar.add(mStringSchoolName+"\n\n");

                }


            }


         for (int j = 0; j <((SoapObject) result1).getPropertyCount(); j++) 
             {

              request = new SoapObject(NAMESPACE, "catalogProductAttributeMediaList");
              request.addProperty("sessionId",sessionId );
              request.addProperty("product",j+1 );
              env.setOutputSoapObject(request);
              androidHttpTransport.call("", env);
              Object resultData1 = env.getResponse();
            //  System.out.println("mStringSchoolName "+resultData1);
              Object property = ((SoapObject) resultData1).getProperty(0);
              String url=(((SoapObject)property).getProperty("url").toString());
              try {
                  imageURL = new URL(url);
                  } 

                 catch (MalformedURLException e) {
                     e.printStackTrace();
                  }

                 try {
                  HttpURLConnection connection= (HttpURLConnection)imageURL.openConnection();
                  connection.setDoInput(true);
                  connection.connect();
                     InputStream inputStream = connection.getInputStream();
                       bitmap = BitmapFactory.decodeStream(inputStream);//Convert to bitmap
                      bitmapArray.add(bitmap);
                  }
                 catch (IOException e) {

                      e.printStackTrace();
                 }

              }       


            List<HashMap<String, Bitmap>> list= new ArrayList<HashMap<String,Bitmap>>();

            for(Bitmap var: bitmapArray)
            {
             HashMap<String,Bitmap> map= new HashMap<String,Bitmap>();
                System.out.println("Item is: " + var);

                 image_view.setImageBitmap(var);

                 map.put("key",var);

                list.add(map);

            }


             String[] from = { "key" };  
            int[] to = {R.id.imageview};

            SimpleAdapter adapter = new SimpleAdapter(this,list,R.layout.activity_main,from,to);
            ListView listView = (ListView) findViewById(R.id.lv);
            listView.setAdapter(adapter); 

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


    }

}

here in output i only get last image by using **image_view.setImageBitmap(var);** in hashmap because of not adding this in listview.but i don't want this. what i want is to display images from bitmap array that contain array of bitmaps(images)  in listview one by one at run time i.e load one by one using simple adapter.
     so please suggest me something to acheive above mentioned requirement.I will be very thankful for your suggestions.
公共类MainActivity扩展活动{
私有静态最终字符串NAMESPACE=“urn:Magento”;
私有静态最终字符串URL=“magento的URL”;
位图;
URL imageURL=null;
ArrayList bitmapArray=新的ArrayList();
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy=新建StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(策略);
TextView tv1=(TextView)findViewById(R.id.tv);
ListView lv=(ListView)findViewById(R.id.lv);
ImageView image\u view=(ImageView)findViewById(R.id.ImageView);
试一试{
SoapSerializationEnvelope env=新的SoapSerializationEnvelope(
第11版);
env.dotNet=false;
env.xsd=SoapSerializationEnvelope.xsd;
env.enc=SoapSerializationEnvelope.enc;
SoapObject请求=新的SoapObject(名称空间,“登录”);
请求。addProperty(“用户名”、“支票”);
请求添加属性(“apiKey”、“123456”);
环境setOutputSoapObject(请求);
HttpTransportSE androidHttpTransport=新的HttpTransportSE(URL,3600000);
androidHttpTransport.call(“,env);
对象结果=env.getResponse();
Log.d(“sessionId”,result.toString());
SoapSerializationEnvelope env1=新的SoapSerializationEnvelope(
第11版);
env1.dotNet=false;
env1.xsd=SoapSerializationEnvelope.xsd;
env1.enc=SoapSerializationEnvelope.enc;
SoapObject request1=新的SoapObject(名称空间,“登录”);
请求1.添加属性(“用户名”、“支票”);
请求1.添加属性(“apiKey”、“123456”);
env1.setOutputSoapObject(请求1);
HttpTransportSE androidHttpTransport1=新的HttpTransportSE(URL,60000);
androidHttpTransport1.call(“,env1);
对象result2=env1.getResponse();
字符串sessionId=result.toString();
请求=新的SoapObject(名称空间,“catalogProductList”);
请求。添加属性(“父类别”、“2”);
request.addProperty(“sessionId”,sessionId);
请求.addProperty(“productId”,1);
环境setOutputSoapObject(请求);
androidHttpTransport.call(“,env);
对象result1=env.getResponse();
ArrayList ar=新的ArrayList();

对于(inti=0;i您需要使用自定义适配器在列表视图中显示图像和文本。。。 我正在发布此链接…请查看此链接


谢谢Akshey,最后我考虑了你的建议并做了一些修改,解决了我的问题。你节省了我的时间。非常感谢。