Я создаю просмотрщик PDF для android, в настоящее время у меня это вроде работает здесь 3 из открытых PDF-файлов по нажатию кнопки, однако остальные 7 не работают, даже если они используют один и тот же код. Я проверил, если они ссылаются на правильные PDF-файлы, и они. Не совсем уверен в проблеме, поскольку код работает для трех из них, но не для других 7.
Любая помощь будет принята.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
PdfViewer pdfViewer;
View rootView = inflater.inflate(R.layout.fragmentlist, container, false);
listView =(ListView) rootView.findViewById(R.id.list);
String[] values = new String[] {
"Systems Architecture Revision",
"Memory And Storage Revision",
"Systems Revision",
"Networks",
"Security",
"Legal And Ethical Revision",
"Algorithms Revision",
"Programming",
"Data Revision",
"Logic Revision"
};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, values);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
listView.getItemAtPosition(position);
if (position == 0) {
PdfViewer sampleFragment = new PdfViewer();
Bundle args = new Bundle();
args.putInt("key", 0);
sampleFragment.setArguments(args);
getFragmentManager()
.beginTransaction()
.replace(R.id.content, sampleFragment)
.addToBackStack(null)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit();
}
else if (position == 1) {
PdfViewer sampleFragment = new PdfViewer();
Bundle args = new Bundle();
args.putInt("key", 1);
sampleFragment.setArguments(args);
getFragmentManager()
.beginTransaction()
.replace(R.id.content, sampleFragment)
.addToBackStack(null)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit();
}
else if (position == 2) {
PdfViewer sampleFragment = new PdfViewer();
Bundle args = new Bundle();
args.putInt("key", 2);
sampleFragment.setArguments(args);
getFragmentManager()
.beginTransaction()
.replace(R.id.content, sampleFragment)
.addToBackStack(null)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit();
}
else if (position == 3) {
PdfViewer sampleFragment = new PdfViewer();
Bundle args = new Bundle();
args.putInt("key", 3);
sampleFragment.setArguments(args);
getFragmentManager()
.beginTransaction()
.replace(R.id.content, sampleFragment)
.addToBackStack(null)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit();
}
else if (position == 4) {
PdfViewer sampleFragment = new PdfViewer();
Bundle args = new Bundle();
args.putInt("key", 4);
sampleFragment.setArguments(args);
getFragmentManager()
.beginTransaction()
.replace(R.id.content, sampleFragment)
.addToBackStack(null)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit();
}
else if (position == 5) {
PdfViewer sampleFragment = new PdfViewer();
Bundle args = new Bundle();
args.putInt("key", 5);
sampleFragment.setArguments(args);
getFragmentManager()
.beginTransaction()
.replace(R.id.content, sampleFragment)
.addToBackStack(null)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit();
}
else if (position == 6) {
PdfViewer sampleFragment = new PdfViewer();
Bundle args = new Bundle();
args.putInt("key", 6);
sampleFragment.setArguments(args);
getFragmentManager()
.beginTransaction()
.replace(R.id.content, sampleFragment)
.addToBackStack(null)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit();
}
else if (position == 7) {
PdfViewer sampleFragment = new PdfViewer();
Bundle args = new Bundle();
args.putInt("key", 7);
sampleFragment.setArguments(args);
getFragmentManager()
.beginTransaction()
.replace(R.id.content, sampleFragment)
.addToBackStack(null)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit();
}
else if (position == 8) {
PdfViewer sampleFragment = new PdfViewer();
Bundle args = new Bundle();
args.putInt("key", 8);
sampleFragment.setArguments(args);
getFragmentManager()
.beginTransaction()
.replace(R.id.content, sampleFragment)
.addToBackStack(null)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit();
}
else if (position == 9) {
PdfViewer sampleFragment = new PdfViewer();
Bundle args = new Bundle();
args.putInt("key", 9);
sampleFragment.setArguments(args);
getFragmentManager()
.beginTransaction()
.replace(R.id.content, sampleFragment)
.addToBackStack(null)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit();
}
}
});
return rootView;
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.pdf_viewer, container, false);
pdfView = (PDFView) rootView.findViewById(R.id.pdfView);
pdfView = (PDFView) rootView.findViewById(R.id.pdfView);
int pos=0;
if (getArguments() != null) {
pos = getArguments().getInt("key");
}
if (pos == 0) {
displayFromAsset("systemsarchitecture.pdf");
}
else if (pos == 1) {
displayFromAsset("memory.pdf");
}
else if (pos == 2) {
displayFromAsset("systems.pdf");
}
else if (pos == 3) {
displayFromAsset("networks.pdf");
}
else if (pos == 4) {
displayFromAsset("security.pdf");
}
else if (pos == 5) {
displayFromAsset("legal.pdf");
}
else if (pos == 6) {
displayFromAsset("algorithms.pdf");
}
else if (pos == 7) {
displayFromAsset("programming.pdf");
}
else if (pos == 8) {
displayFromAsset("data.pdf");
}
else if (pos == 9) {
displayFromAsset("logic.pdf");
}
setHasOptionsMenu(true);
return rootView;
}