java构造函数SimpleAdapter类中的SimpleAdapter无法应用于给定类型

时间:2016-04-11 14:56:14

标签: java android listview android-studio xml-parsing

SimpleAdapter中的Java构造函数SimpleAdapter在我写下行时无法应用于给定类型我在下面提到它为什么以及如何解决此错误。

private class AsyncCallWS extends AsyncTask<String, Void, Void> {
    private Exception exception;
    @Override
    protected Void doInBackground(String... params) {
        try {
            //Invoke webservice
            displayText = WebService.invokeHelloWorldWS(spin2, spin3, spin1, "search_availability");
            ListView myList=(ListView)findViewById(android.R.id.list);

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

            XmlParser parser = new XmlParser();
            String xml = null; // getting XML
            try {
                xml = parser.getXmlFormUrl(URL);
            } catch (IOException e) {
                e.printStackTrace();
            }
            Document doc = parser.getDomElement(xml); // getting DOM element
            NodeList nl = doc.getElementsByTagName(KEY_ITEM);
            // looping through all item nodes <item>
            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(KEY_ID,  parser.getValue(e, KEY_ID));
                map.put(KEY_NAME, parser.getValue(e, KEY_NAME));
                map.put(KEY_COST, "Rs." + parser.getValue(e, KEY_COST));
                map.put(KEY_DESC, parser.getValue(e, KEY_DESC));

                // adding HashList to ArrayList
                menuItems.add(map);
            }
            // Adding menuItems to ListView
            ListAdapter adapter = new SimpleAdapter(this, menuItems,
                    R.layout.list_item,
                    new String[] { KEY_NAME, KEY_DESC, KEY_COST }, new int[] {
                    R.id.name, R.id.desciption, R.id.cost });

            setListAdapter(adapter);

        }catch (Exception e) {
            this.exception = e;
            return null;
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {


        //Set response
        tv.setText(displayText);
        //Make ProgressBar invisible
        pg.setVisibility(View.INVISIBLE);
    }

    @Override
    protected void onPreExecute() {
        //Make ProgressBar invisible
        pg.setVisibility(View.VISIBLE);
    }

    @Override
    protected void onProgressUpdate(Void... values) {
    }

}

此行

ListAdapter adapter = new SimpleAdapter(this, menuItems,
                    R.layout.list_item,
                    new String[] { KEY_NAME, KEY_DESC, KEY_COST }, new int[] {
                    R.id.name, R.id.desciption, R.id.cost });

我不知道为什么会出现此错误,以及如何解决此错误。

0 个答案:

没有答案