Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
显示从Soap Webservice到listview Android的字符串数组_Android_Arrays_Android Listview_Ksoap2 - Fatal编程技术网

显示从Soap Webservice到listview Android的字符串数组

显示从Soap Webservice到listview Android的字符串数组,android,arrays,android-listview,ksoap2,Android,Arrays,Android Listview,Ksoap2,我正在尝试向listview显示我的数组soap操作结果。我设法检索项目并将其存储为字符串,但是,我似乎无法将所有字符串都放入listview。我做错了什么??当我登录.d时,它以正确的顺序显示所有内容(这正是我想要的)。但是,当我将其添加到搜索结果中时,它只显示最后的详细信息 try { androidHttpTransport.call(SOAP_ACTION, envelope); SoapObjec

我正在尝试向listview显示我的数组soap操作结果。我设法检索项目并将其存储为字符串,但是,我似乎无法将所有字符串都放入listview。我做错了什么??当我登录.d时,它以正确的顺序显示所有内容(这正是我想要的)。但是,当我将其添加到搜索结果中时,它只显示最后的详细信息

 try
            {
                androidHttpTransport.call(SOAP_ACTION, envelope);
                SoapObject response = (SoapObject)envelope.getResponse();

                for (int i = 0; i < response.getPropertyCount(); i++) {
                    Object property = response.getProperty(i);
                    if (property instanceof SoapObject) {

                        ArrayList<SearchResults> results = new ArrayList<SearchResults>();
                         SearchResults sr1 = new SearchResults();

                      SoapObject info = (SoapObject) property;
                      String description = info.getProperty("description").toString();
                      String name = info.getProperty("name").toString();
                      String date = info.getProperty("date").toString(); 

                        Log.d("This is the list of id:",description);
                        Log.d("This is the list of name:",name);
                        Log.d("This is the list of date:",date);

                 sr1.setDescription(description);
                     sr1.setName(name);
                     sr1.setDate(date);                 
                     results.add(sr1);

                       final ListView lv1 = (ListView) findViewById(R.id.ListView01);
                       lv1.setAdapter(new MyCustomBaseAdapter(this, results));

                       lv1.setOnItemClickListener(new OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> a, View v, int position, long id) { 
                         Object object = lv1.getItemAtPosition(position);
                         SearchResults fullObject = (SearchResults)object;
                         Toast.makeText(second.this, "You have chosen: " + " " + fullObject.getName(), Toast.LENGTH_LONG).show();

                      //   return;
                        }  
                      });  
             }
           }
         }
试试看
{
调用(SOAP_操作,信封);
SoapObject响应=(SoapObject)信封.getResponse();
对于(int i=0;i
这是因为每次在for循环中创建一个新的
ArrayList
,所以它会在创建的
ArrayList
中重写最后一个数据

应该是,

ArrayList<SearchResults> results = new ArrayList<SearchResults>();
for (int i = 0; i < response.getPropertyCount(); i++) {
  SearchResults sr1 = new SearchResults();
  // fetch results
} 
// update the List
ListView lv1 = (ListView) findViewById(R.id.ListView01);   
lv1.setAdapter(new MyCustomBaseAdapter(this, results));
ArrayList结果=新建ArrayList();
对于(int i=0;i
试试这个: 我已经更改了代码。因为listview适配器将结果绑定到循环之外

  ArrayList<SearchResults> results = new ArrayList<SearchResults>();
  for (int i = 0; i < response.getPropertyCount(); i++) {
                Object property = response.getProperty(i);
                if (property instanceof SoapObject) {


                     SearchResults sr1 = new SearchResults();

                  SoapObject info = (SoapObject) property;
                  String description = info.getProperty("description").toString();
                  String name = info.getProperty("name").toString();
                  String date = info.getProperty("date").toString(); 

                    Log.d("This is the list of id:",description);
                    Log.d("This is the list of name:",name);
                    Log.d("This is the list of date:",date);

             sr1.setDescription(description);
                 sr1.setName(name);
                 sr1.setDate(date);                 
                 results.add(sr1);
}
}
                   final ListView lv1 = (ListView) findViewById(R.id.ListView01);
                   lv1.setAdapter(new MyCustomBaseAdapter(this, results));

                   lv1.setOnItemClickListener(new OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> a, View v, int position, long id) { 
                     Object object = lv1.getItemAtPosition(position);
                     SearchResults fullObject = (SearchResults)object;
                     Toast.makeText(second.this, "You have chosen: " + " " + fullObject.getName(), Toast.LENGTH_LONG).show();

                  //   return;
                    }  
                  });  
         }
ArrayList结果=新建ArrayList();
对于(int i=0;i
您的代码错误。我甚至可以用你的代码显示任何东西。请检查我在上面勾选的正确答案。。谢谢你的努力~