• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Xml Parsing in android

krishnaveni

Well-Known Member
Hi i wrote one xml parsing example.here i have to get the data information from mysql database and display it in android emulator successfully.
This is my code:
Code:
public class CustomizedListView extends Activity {
    // All static variables
    static final String URL = "http://192.168.1.168/pro/orderdetails.xml";
    // XML node keys
    static final String KEY_SONG = "Order"; // parent node
    static final String KEY_ID = "orderid";
    static final String KEY_TITLE = "orderid";
    static final String KEY_ARTIST = "payment_method";
    static final String KEY_DURATION = "total";
    
    
    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_SONG);
        // 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_ARTIST, parser.getValue(e, KEY_ARTIST));
        
            
            // 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) {
                            
                
               String Total = ((TextView) view.findViewById(R.id.duration)).getText().toString();
                
                // Starting new intent
                Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
                
               
                in.putExtra(KEY_DURATION, Total);
              
                startActivity(in);                    
            }
        });        
    }    
}

This is SingleMenuItem.java class is:
Code:
public class SingleMenuItemActivity  extends Activity {
    
    // XML node keys
   static final String KEY_DURATION = "total";
    @Override

        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.single_list_item);

        // getting intent data
        Intent in = getIntent();

        // Get XML values from previous intent
        String total = in.getStringExtra(KEY_DURATION);
       

        // Displaying all values on the screen
       
        TextView lblDesc = (TextView) findViewById(R.id.description_label);

       
        lblDesc.setText(total);
        }
}

Here i have to successfully displayed on android emulator. but i wish to display on first page orderid and payment_method only.then it is move to next page means have to display total for that particular id.please give me solutions.how can i to do.i wish to my output is :

13(orderid) Phone ordering(payment_method)
14(orderid) check (payment_method)
15(orderid) Phone ordering(payment_method)
if i clicked 13 means that particular order total only displayed on next activity.

200(total)
How is to do.please help me.
 
i got the answer.if u need hide the "description" field by adding andorid:visibility="gone" to description label in your xml file. So that the description filed will be present in listview but it won't be visible.
 
Back
Top Bottom