hi all
i using 40 PDF file
this mean i need to do 40 mainActivity ????
package com.example.androidtabmenucustomizeactionbaritemclick;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import com.github.barteksc.pdfviewer.PDFView;
import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener;
import com.github.barteksc.pdfviewer.listener.OnPageChangeListener;
import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle;
import com.shockwave.pdfium.PdfDocument;
import java.util.List;
public class pdffiel extends Activity implements OnPageChangeListener,OnLoadCompleteListener{
private static final String TAG = pdffiel.class.getSimpleName();
public static final String SAMPLE_FILE = "fasil9.pdf";
PDFView pdfView;
Integer pageNumber = 0;
String pdfFileName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pdf);
pdfView= (PDFView)findViewById(R.id.pdfView);
}
private void displayFromAsset(String assetFileName) {
pdfFileName = assetFileName;
pdfView.fromAsset(SAMPLE_FILE)
.defaultPage(pageNumber)
.enableSwipe(true)
.swipeHorizontal(false)
.onPageChange(this)
.enableAnnotationRendering(true)
.onLoad(this)
.scrollHandle(new DefaultScrollHandle(this))
.spacing(10)
.load();
}
@Override
public void onPageChanged(int page, int pageCount) {
pageNumber = page;
setTitle(String.format("%s %s / %s", pdfFileName, page + 1, pageCount));
}
@Override
public void loadComplete(int nbPages) {
PdfDocument.Meta meta = pdfView.getDocumentMeta();
printBookmarksTree(pdfView.getTableOfContents(), "-");
}
public void printBookmarksTree(List<PdfDocument.Bookmark> tree, String sep) {
for (PdfDocument.Bookmark b : tree) {
Log.e(TAG, String.format("%s %s, p %d", sep, b.getTitle(), b.getPageIdx()));
if (b.hasChildren()) {
printBookmarksTree(b.getChildren(), sep + "-");
}
}
}
}
You have one activity and you have to load different PDFs depending on something (I don't know how does your app should work). Probably path to document will be passed via Intent
thank you for reply
it is work fine
can you tell me with Example
Sorry, I don't understand your comment
i mean how i make 40 pdf ???
in mainActivity i have only 1 pdf
how i make 40 pdf ?
You have to pass path to PDF document when opening your activity, Android has Intents for such cases
Just incase 40 pdf meas load page 40 you pass the page number via the intent to start at a page number.
thank you for reply
pls i want Example code
I am a beginner in the android
I won't give you example code, it is core Android mechanism, please read Android documentation first.
hi, sapq..
Use one Main Activity, Put one Spinner Above PdfViewer, Load spinner with your 40 pdf books name, On Selection change call pdf viewer function with your Spinner value.. It's very basic idea, you need to read more..
thank you i fix my problem
i use extends Fragment
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
// get the button view
fashionImg = (ImageView) getView().findViewById(R.id.imageView7);
// set a onclick listener for when the button gets clicked
fashionImg.setOnClickListener(new View.OnClickListener() {
// Start new list activity
public void onClick(View v) {
Intent Intent = new Intent(getActivity(),minb.class);
startActivity(Intent);
}
});
fashionImg = (ImageView) getView().findViewById(R.id.imageView);
// set a onclick listener for when the button gets clicked
fashionImg.setOnClickListener(new View.OnClickListener() {
// Start new list activity
public void onClick(View v) {
Intent Intent = new Intent(getActivity(),
aloom.class);
startActivity(Intent);
}
});
fashionImg = (ImageView) getView().findViewById(R.id.imageView10);
// set a onclick listener for when the button gets clicked
fashionImg.setOnClickListener(new View.OnClickListener() {
// Start new list activity
public void onClick(View v) {
Intent Intent = new Intent(getActivity(),minb.class);
startActivity(Intent);
}
});
}
Most helpful comment
I won't give you example code, it is core Android mechanism, please read Android documentation first.