0

android JSON parsing pagination how to i do with 10 item in a list in single page and left out list item goes to another page list item

this is my code

public class First extends ListActivity {

private ProgressDialog pDialog;

// URL to get contacts JSON
private static String url = "http://ampndesigntest.com/pandit/contacts.css";

// JSON Node names
private static final String TAG_CONTACTS = "contacts";
private static final String TAG_ID = "id";
private static final String TAG_NAME = "name";
private static final String TAG_EMAIL = "email";
private static final String TAG_ADDRESS = "address";
private static final String TAG_GENDER = "gender";
private static final String TAG_PHONE = "phone";
private static final String TAG_PHONE_MOBILE = "mobile";
private static final String TAG_PHONE_HOME = "home";
private static final String TAG_PHONE_OFFICE = "office";

// contacts JSONArray
JSONArray contacts = null;

// Hashmap for ListView
ArrayList<HashMap<String, String>> contactList;

Button next,previous;
private TextView title;
private int increment = 0;
private int pageCount ;
public int TOTAL_LIST_ITEMS = 100;
public int NUM_ITEMS_PAGE   = 10;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.first);



    title=(TextView)findViewById(R.id.title);
    next=(Button)findViewById(R.id.next);
    previous=(Button)findViewById(R.id.prev);

    previous.setEnabled(false);


    contactList = new ArrayList<HashMap<String, String>>();
        int val = TOTAL_LIST_ITEMS%NUM_ITEMS_PAGE;
        val = val==0?0:1;
        pageCount = TOTAL_LIST_ITEMS/NUM_ITEMS_PAGE+val;



    ListView lv = getListView();

    // Listview on item click listener
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            // getting values from selected ListItem
            String name = ((TextView) view.findViewById(R.id.name))
                    .getText().toString();
            String cost = ((TextView) view.findViewById(R.id.email))
                    .getText().toString();
            String description = ((TextView) view.findViewById(R.id.mobile))
                    .getText().toString();

            // Starting single contact activity
            Intent in = new Intent(getApplicationContext(),
                    SingleContactActivity.class);
            in.putExtra(TAG_NAME, name);
            in.putExtra(TAG_EMAIL, cost);
            in.putExtra(TAG_PHONE_MOBILE, description);
            startActivity(in);

        }
    });

    // Calling async task to get json
    new GetContacts().execute();
}

/**
 * Async task class to get json by making HTTP call
 * */
private class GetContacts extends AsyncTask<Void, Void, Void> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        // Showing progress dialog
        pDialog = new ProgressDialog(First.this);
        pDialog.setMessage("Please wait...");
        pDialog.setCancelable(false);
        pDialog.show();

    }
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
user3066085
  • 128
  • 1
  • 8
  • Android providing smooth scrolling to display many items quickly while scrolling then why you want to go with Pagination. I think its better to use List with Scrolling. – Pratik Butani Jan 30 '14 at 10:51
  • if we have 10,000 of list items then what will we have dun – user3066085 Jan 30 '14 at 11:23
  • my motive is that i want to use single list and with navigation page list items – user3066085 Jan 30 '14 at 11:24
  • then you can search that item, and it is also problem in pagination like if you want to go "8000" or "9000" record then how you go. – Pratik Butani Jan 30 '14 at 11:27
  • we have option to switch items .but us peoples are not want to do any hard work u can understand if he want to go directly any activity then we should do that .actual i have a project us based a industry project so there is this type requirement to do do this .....data shown in list form and pagination also so i have need – user3066085 Jan 30 '14 at 12:09
  • Okay. You can store all json data in ArrayList and then display 10by10 as you wish. – Pratik Butani Jan 30 '14 at 12:14

0 Answers0