<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/selection"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
/>
</LinearLayout>
package com.commonsware.android.resources;
import java.util.ArrayList;
import org.xmlpull.v1.XmlPullParser;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class XMLResourceDemo extends ListActivity {
TextView selection;
ArrayList<string> items=new ArrayList<string>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
selection=(TextView)findViewById(R.id.selection);
try{
XmlPullParser xpp =getResources().getXml(R.xml.words);
while(xpp.getEventType()!=XmlPullParser.END_DOCUMENT){
if(xpp.getEventType()==XmlPullParser.START_TAG){
if(xpp.getName().equals("word")){
items.add(xpp.getAttributeValue(0));
}
}
xpp.next();
}
}
catch(Throwable t){
Toast.makeText(this, "실패 : "+t.toString(),4000).show();
}
setListAdapter(new ArrayAdapter<string>(this,android.R.layout.simple_list_item_1,items));
}
public void onListItemClick(ListView parent, View v , int position, long id){
selection.setText(items.get(position).toString());
}
}