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

Apps XML Parser with Pagination

krishnaveni

Well-Known Member
Hi i have to develop one xml parser example with pagination examples.
Here i have to display 10-10 item per page.how is develop this.please give me some idea.

this is my android code:
Code:
package com.example.androidhive;

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.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class CustomizedListView extends Activity {
    // All static variables
    static final String URL = "http://192.168.1.168/xcart432pro/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));
            map.put(KEY_DURATION, parser.getValue(e, KEY_DURATION));
            
            // 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 Orderid= ((TextView) view.findViewById(R.id.title)).getText().toString();
                String Price = ((TextView) view.findViewById(R.id.duration)).getText().toString();
                
                String Description = ((TextView) view.findViewById(R.id.artist)).getText().toString();
                
                // Starting new intent
                Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
                
                 in.putExtra(KEY_TITLE, Orderid);
                in.putExtra(KEY_DURATION, Price);
                in.putExtra(KEY_ARTIST, Description);
                startActivity(in);                    
            }
        });        
    }    
}

In this link http://192.168.1.168/xcart432pro/orderdetails.xml have 200 products.but i wish to display 10 products only.then the next 10 product is display same activity after load few mints.how can i develop this.please give me some ideas.
 
Back
Top Bottom