How to convert a string containing numbers separated by comma to Integer in java?

136 views Asked by At

I have added AndroidPdfViewer library in my app, and i added a single pdf file in assets folder but i want to show it chapter wise as i added chapter wise buttons on home screen, i am sending page numbers as a string using putExtra to the pdfActivity to show only these pages of the pdf file. In pdfActivity i am unable to convert this string to integer.
HomeActivity.java

 i.putExtra("pages","1,5,10,12,15"); startActivity(i);

PdfActivity.java

 Intent intent = getIntent();
// String Pages = intent.getStringExtra("pages");
// int PageNumbers =Integer.parseInt(Pages.toString());
// Integer PageNumbers = Integer.valueOf(Pages);

int PageNumbers = intent.getIntExtra("pages", 0);

pdfView.fromAsset(result)
                .pages(PageNumbers)    //.pages(1,5,10,12,15)
                .enableDoubletap(false)
                .enableAntialiasing(true)
                .pageFitPolicy(FitPolicy.WIDTH)
                .load();

Only page number 1 is visible and others are not showing.
How to show Pages 1,5,10,12,15 of pdf file as data sent from HomeActivity?

1

There are 1 answers

0
Smutje On BEST ANSWER

Is there a reason you don't save the list of pages directly via an array and putExtra?

HomeActivity.java

int[] pages = {1, 5, 10, 12, 15};
i.putExtra("pages", pages);

PdfActivity.java

int[] pages = intent.getIntArrayExtra("pages");
pdfView.fromAsset(result)
       .pages(pages)