您好我有这个SimpleAdapter,以便在ListView中显示一些通知。这些通知在ArrayList
本地人。这是代码:
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);
问题在于它在这里向我显示了三个错误。第一个是在本地主义者并说“地方主义者无法解决变量”。
第二个和第三个在
lv.setAdapter(adapter);
一个点上写着“令牌上的语法错误,错位的构造”,另一个位于括号内的适配器上,表示“令牌上的语法错误”适配器“,此令牌后面的VariableDeclaratorId” 。我的第二个和第三个错误是由于第一个错误引起的。你有任何想法如何解决这个问题吗?提前做了很多!
编辑: 在其他活动中声明并创建了本地人 这是代码:
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);
}
答案 0 :(得分:2)
从你的评论中,我想我知道发生了什么。您的Asynctask
看起来与您的Adapter
位于不同的文件中。有几种方法可以解决这个问题。一种方法是在任务完成后使用interface
在Adapter
中设置变量。
See this answer用于为interface
创建AsyncTask
。
更简单的方法是让您的AsyncTask
成为Adapter
所在的内部类,并使localist
成为该类的成员变量,以便两者都可以访问它。然后,您可以在Adapter
中设置ListView
和onPostExecute()
。