public class ParsersDemo extends Activity { ListView lvList; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lvList = (ListView) findViewById(R.id.lvList); SAXParser saxParser; try { saxParser = SAXParserFactory.newInstance().newSAXParser(); saxParser.parse(getResources().openRawResource(R.raw.test),new StudentHandler()); } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } DataHandler dataHandler = new DataHandler(getApplicationContext()); dataHandler.insertStudent(new StudentHandler().getData()); dataHandler.closeDataBase(); lvList.setAdapter(new MyAdapter(new StudentHandler().getData())); } public class MyAdapter extends BaseAdapter { Vector<Student> vecStudent; MyAdapter(Vector<Student> vecStu) { vecStudent = vecStu; } @Override public int getCount() { // TODO Auto-generated method stub return vecStudent.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return null; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { Student student = vecStudent.get(position); convertView = (LinearLayout)getLayoutInflater().inflate(R.layout.list_cell, null); TextView tvsno = (TextView) convertView.findViewById(R.id.sno); TextView tvsname = (TextView) convertView.findViewById(R.id.sname); TextView tvcity = (TextView) convertView.findViewById(R.id.city); tvsno.setText(student.sno); tvsname.setText(student.name); tvcity.setText(student.city); return convertView; } } }
Tuesday, 2 October 2012
Sax Parsing
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment