变量“适配器”和声明 final 中的问题。我的 IDE 不断告诉“适配器”需要被声明为最终版本,我在哪里以及如何做?这让我站住了,我似乎无法从那里继续前进。请帮忙。它在这里引用此代码和问题:Android ImageView from ListView
package com.example.androidhive;
import java.util.ArrayList;
import java.util.HashMap;
import android.content.Intent;
import android.widget.TextView;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
public class CustomizedListView extends Activity {
// All static variables
static final String URL = "http://imforchange.org/international-movement-for-change/testing/data.xml";
// XML node keys
static final String KEY_EVENT = "event"; // parent node
static final String KEY_ID = "eventId";
static final String KEY_TITLE = "eventName";
static final String KEY_DESCRIPTION = "eventDescription";
static final String KEY_ABSTRACT = "eventAbstract";
static final String KEY_DATE = "eventDate";
static final String KEY_PRICE = "eventPrice";
static final String KEY_LINK = "eventLink";
static final String KEY_ADDRESS = "eventAddress";
static final String KEY_CUSTOM_LINK = "eventCustomlink";
static final String KEY_PICTURE = "eventPicture";
static final String KEY_ICON = "eventIcon";
ListView list;
LazyAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
LazyAdapter adapter = new LazyAdapter(this, songsList);
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML from URL
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_EVENT);
// 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(KEY_ID, parser.getValue(e, KEY_ID));
map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
map.put(KEY_DESCRIPTION, parser.getValue(e, KEY_DESCRIPTION));
map.put(KEY_ABSTRACT, parser.getValue(e, KEY_ABSTRACT));
map.put(KEY_DATE, parser.getValue(e, KEY_DATE));
map.put(KEY_PRICE, parser.getValue(e, KEY_PRICE));
map.put(KEY_LINK, parser.getValue(e, KEY_LINK));
map.put(KEY_ADDRESS, parser.getValue(e, KEY_ADDRESS));
//map.put(KEY_CUSTOM_LINK, parser.getValue(e, KEY_CUSTOM_LINK));
map.put(KEY_PICTURE, parser.getValue(e, KEY_PICTURE));
map.put(KEY_ICON, parser.getValue(e, KEY_ICON));
// adding HashList to ArrayList
songsList.add(map);
}
list=(ListView)findViewById(R.id.list);
// Getting adapter by passing xml data ArrayList
adapter=new LazyAdapter(this, songsList);
list.setAdapter(adapter);
// Click event for single list row
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// Get the item that was clicked
HashMap<String, String> map = adapter.getItem(position);
// Starting new intent
Intent in = new Intent(getApplicationContext(), DetailView.class);
in.putExtra(KEY_TITLE, map.get(KEY_TITLE));
in.putExtra(KEY_PICTURE, map.get(KEY_PICTURE));
in.putExtra(KEY_DESCRIPTION, map.get(KEY_DESCRIPTION));
in.putExtra(KEY_PRICE, map.get(KEY_PRICE));
in.putExtra(KEY_LINK, map.get(KEY_LINK));
startActivity(in);
}
});
}
}