0

您好我正在尝试使用 android 中的 .net Web 服务使用 hashmap<> 获取值。我有定制的适配器,我正在尝试这样做。

SoapObject folderResponse = (SoapObject)envelope.getResponse();

                Log.i("AllFolders", folderResponse.toString());

                String[] folderslist = new String[folderResponse.getPropertyCount()];        

//getting values using folderslist.

                ArrayList<HashMap<String, String>> hashfoldersList = new ArrayList <HashMap<String, String> >();   

//But I want hashfoldersList list in my custamized adapter.

                for(i=0; i<folderResponse.getPropertyCount(); i++) {

                    SoapObject SingleFolder = (SoapObject)folderResponse.getProperty(i);

                    Log.i("SingleFolder", SingleFolder.toString());

                        ID= SingleFolder.getProperty(0).toString();
                        KEY_Name = SingleFolder.getProperty(1).toString();
                        ParentID = SingleFolder.getProperty(2).toString();
                        CreatedBy= SingleFolder.getProperty(3).toString();

                        System.out.println(ID);
                        System.out.println(KEY_Name);
                        System.out.println(ParentID);
                        System.out.println(CreatedBy);

                    SoapPrimitive Record =(SoapPrimitive) SingleFolder.getProperty(1);

                        Log.i("Record", Record.toString());

                {

                        folderslist[i] = SingleFolder.getProperty(0).toString();

                }



                XMLParser parser = new XMLParser();
                String xml = parser.getXmlFromUrl(URL); // getting XML from URL
                org.w3c.dom.Document doc = parser.getDomElement(xml); // getting DOM element

                NodeList nl = (NodeList) doc.getElementsByTagName(ID);
                // looping through all song nodes <song>
                for (int i = 0; i < nl.getLength(); i++) {
                    // creating new HashMap
                    HashMap<String, String> map = new HashMap<String, String>();

                    Element e = (Element) nl.item(i);
                    // adding each child node to HashMap key => value

                    map.put(ID, parser.getValue(e, ID));
                    map.put(KEY_Name, parser.getValue(e, KEY_Name));
                    map.put(ParentID, parser.getValue(e, ParentID)); 
                    map.put(CreatedBy, parser.getValue(e, CreatedBy));

                    foldersList.add(map);
                }

                        listview = (ListView)findViewById(R.id.listview);

                        adapter=new LazyAdapter(this, hashfoldersList);   

//My custemized adapter.
                        listview.setAdapter(adapter);

                        listview.setOnItemClickListener(this);
                }

        }

请建议,如何使用 ArrayList> hashfolderlist 获取列表中的值,因为我使用的是 string[] 文件夹列表。当我插入 hashfolderlist 时,它给出了错误。请建议。谢谢

4

1 回答 1

1

伙计,您应该有一个简单的适配器来获取字符串并将其放入列表视图中。第二你应该有2个文本视图

SimpleAdapter adapter = new SimpleAdapter(this, list,
                    R.layout.your_activity, new String[] { "", "" },
                    new int[] { R.id.textview1, R.id.textView2 }

            );

            listView1.setAdapter(adapter);

希望对你有帮助!!

于 2013-04-17T11:49:40.073 回答