get Page index from total page count and per page count - Android java.lang

Android examples for java.lang:Integer

Description

get Page index from total page count and per page count

Demo Code


public class Main{

    public static int getPageCount(int pagetotal, int pagecount) {
        int total = 1;
        //      pagetotal = pagetotal + 1;
        try {/*  w  w w.  j  ava2  s . com*/
            if (pagetotal == 0) {
                return 1;
            }
            if (pagetotal <= pagecount) {
                total = 1;
            } else {
                if (pagetotal % pagecount != 0) {
                    total = pagetotal / pagecount + 1;
                } else {
                    total = pagetotal / pagecount;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            total = 1;
        }
        return total;
    }

}

Related Tutorials