首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android:SimpleAdapter错误

Android:SimpleAdapter错误
EN

Stack Overflow用户
提问于 2013-09-26 22:37:54
回答 1查看 302关注 0票数 0

你好,我有这个SimpleAdapter,以便在ListView.These中显示一些通知,通知在ArrayList区域设置中。以下是代码:

代码语言:javascript
复制
SimpleAdapter adapter = new SimpleAdapter(this,localist, R.layout.rss_list_item,new String[] {"title","pubDate"},new int[] {R.id.title, R.id.pubDate });
    final ListView lv = (ListView) findViewById(android.R.id.list);
    lv.setAdapter(adapter);

问题是,它向我展示了三个错误,here.The第一个错误在地方主义,它说“地方主义者不能被解析为一个变量”。

第二个和第三个在

代码语言:javascript
复制
lv.setAdapter(adapter);

一个在标有“令牌上的语法错误,错位构造”的点处,另一个在括号内的适配器上,上面写着“令牌上的语法错误”适配器,VariableDeclaratorId期望在此令牌之后。我认为第二个和第三个错误是由于第一个错误引起的。你有什么办法解决这个问题吗?提前很多次!

编辑:地方官是在其他活动中声明和创建的,下面是代码:

代码语言:javascript
复制
protected Integer doInBackground(Void... params) {
        ArrayList<HashMap<String, String>> localist = new ArrayList<HashMap<String, String>>();
        String xml = ParseXMLmethods.getXML();
        Document doc = ParseXMLmethods.XMLfromString(xml);
        if (doc != null) {
        NodeList children = doc.getElementsByTagName("item");
        ZERO_FLAG = false;
        if (children.getLength() == 0) {
        ZERO_FLAG = true;
        publishProgress();
        }
        for (int i = 0; i < children.getLength(); i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        Element e = (Element) children.item(i);
        map.put("title", ParseXMLmethods.getValue(e, "title"));
        map.put("pubDate", ParseXMLmethods.getValue(e, "pubDate"));
        map.put("link", ParseXMLmethods.getValue(e, "link"));
        map.put("description",ParseXMLmethods.getValue(e, "description"));
        localist.add(map);

        }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-26 23:10:40

从你的评论中,我想我知道发生了什么。看起来您的Asynctask在一个独立的文件中,而不是您的Adapter。有几种方法可以解决这个问题。一种方法是在任务完成后使用interface来设置Adapter中的变量。

See this answer,用于为AsyncTask创建interface

一个更简单的方法是使您的AsyncTask成为Adapter所在位置的内部类,并使localist成为该类的成员变量,以便两者都能够访问它。然后,您可以将AdapterListView设置为onPostExecute()

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19039868

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档