你好,我有这个SimpleAdapter,以便在ListView.These中显示一些通知,通知在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);问题是,它向我展示了三个错误,here.The第一个错误在地方主义,它说“地方主义者不能被解析为一个变量”。
第二个和第三个在
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);
}发布于 2013-09-26 23:10:40
从你的评论中,我想我知道发生了什么。看起来您的Asynctask在一个独立的文件中,而不是您的Adapter。有几种方法可以解决这个问题。一种方法是在任务完成后使用interface来设置Adapter中的变量。
See this answer,用于为AsyncTask创建interface。
一个更简单的方法是使您的AsyncTask成为Adapter所在位置的内部类,并使localist成为该类的成员变量,以便两者都能够访问它。然后,您可以将Adapter和ListView设置为onPostExecute()。
https://stackoverflow.com/questions/19039868
复制相似问题