Código PHP:
package com.radiosl;
import java.util.ArrayList;
import java.util.HashMap;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import android.app.Activity;
import android.content.Intent;
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://miweb.es/archivo.xml";
// XML node keys
static final String KEY_EMISORA = "emisora"; // parent node
static final String KEY_ID = "id";
static final String KEY_NOMBRE = "nombre";
static final String KEY_GENERO = "genero";
static final String KEY_LOGO = "logo";
static final String KEY_URL = "url";
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>>();
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_EMISORA);
// 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_NOMBRE, parser.getValue(e, KEY_NOMBRE));
map.put(KEY_GENERO, parser.getValue(e, KEY_GENERO));
map.put(KEY_LOGO, parser.getValue(e, KEY_LOGO));
map.put(KEY_URL, parser.getValue(e, KEY_URL));
// 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) {
Intent i = new Intent();
i.putExtra("nombre",CustomizedListView.get(position).get(KEY_NOMBRE));
i.putExtra("genero",CustomizedListView.get(position).get(KEY_GENERO));
i.putExtra("logo",CustomizedListView.get(position).get(KEY_LOGO));
i.putExtra("url",CustomizedListView.get(position).get(KEY_URL));
i.setClass(this, Radio.class);
startActivity(i);
}
});
}
}