package net.inswave.www.xml_de1;
import android.support.v7.app.AppCompatActivity; import android.os.Bundle;
import java.util.ArrayList; import org.xmlpull.v1.XmlPullParser; import android.app.ListActivity; import android.util.Log; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast;
//public class MainActivity extends ListActivity { public class MainActivity extends AppCompatActivity { //@Override
ArrayList<String> items = new ArrayList<String>(); // ArrayList items = new ArrayList();
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
try{ XmlPullParser parser = getResources().getXml(R.xml.name);
while(parser.getEventType() != XmlPullParser.END_DOCUMENT) { if(parser.getEventType() == XmlPullParser.START_TAG) { if(parser.getName().equals("content")) { Log.d("aa",parser.getAttributeValue(0)); items.add(parser.getAttributeValue(0)); } } parser.next(); } }catch(Throwable t) { Log.d("bb","error"); }
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items); ListView list=(ListView)findViewById(R.id.list) ; //list.setListAdapter(adapter); list.setAdapter(adapter);
}
public void onListItemClick(ListView parent, View v, int position, long id) { Toast.makeText(this, items.get(position).toString(), Toast.LENGTH_LONG ).show(); Log.d("cc",items.get(position).toString()); }
}
|