Android 我正在使用Pdf查看器库打开Pdf文件。它显示pdf加载时间很长
我尝试了pdfView库,我添加了pdfView库jar和所有东西。但它只显示加载PDF页面。我的pdf文件在资产文件夹中 有谁能帮我找到解决办法吗? 我在下面提到了我的代码 谢谢Android 我正在使用Pdf查看器库打开Pdf文件。它显示pdf加载时间很长,android,Android,我尝试了pdfView库,我添加了pdfView库jar和所有东西。但它只显示加载PDF页面。我的pdf文件在资产文件夹中 有谁能帮我找到解决办法吗? 我在下面提到了我的代码 谢谢 package com.example.pdfviewer; import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class MainActivity extends PdfViewerAc
package com.example.pdfviewer;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends PdfViewerActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
}
public int getPreviousPageImageResource() { return R.drawable.left_arrow; }
public int getNextPageImageResource() { return R.drawable.right_arrow; }
public int getZoomInImageResource() { return R.drawable.zoom_in; }
public int getZoomOutImageResource() { return R.drawable.zoom_out; }
public int getPdfPasswordLayoutResource() { return R.layout.pdf_file_password; }
public int getPdfPageNumberResource() { return R.layout.dialog_pagenumber; }
public int getPdfPasswordEditField() { return R.id.etPassword; }
public int getPdfPasswordOkButton() { return R.id.btOK; }
public int getPdfPasswordExitButton() { return R.id.btExit; }
public int getPdfPageNumberEditField() { return R.id.pagenum_edit; }
}
我也遇到了同样的问题,但我解决了。。。 您给定的代码是正确的,只要检查您正在使用的文件的路径是否正确就可以了。在我的项目中,我在这一点上犯了错误,所以这可能会解决你的问题。作为你的参考,我给你我的代码
private File currentDir;
private FileArrayAdapter file_adapter;
String path;
@SuppressLint("SdCardPath") @Override
public void onClick(View v) {
// TODO Auto-generated method stub
currentDir = new File("/sdcard/");
fill(currentDir);
}
@SuppressLint("SdCardPath") private void fill(File f)
{
File[]dirs = f.listFiles();
Faculty_Notes.this.setTitle("Current Dir: "+f.getName());
List<Option>dir = new ArrayList<Option>();
List<Option>fls = new ArrayList<Option>();
try{
for(File ff: dirs)
{
if(ff.isDirectory())
dir.add(new Option(ff.getName(),"Folder",ff.getAbsolutePath()));
else
{
if(ff.getName().endsWith(".pdf"))
{
fls.add(new Option(ff.getName(),"File Size: "+ff.length(),ff.getAbsolutePath()));
}
}
}
}catch(Exception e)
{
e.printStackTrace();
}
Collections.sort(dir);
Collections.sort(fls);
dir.addAll(fls);
if(!f.getName().equalsIgnoreCase("/sdcard"))
dir.add(0,new Option("..","Parent Directory",f.getParent()));
file_adapter = new FileArrayAdapter(Faculty_Notes.this,R.layout.file_view,dir);
Faculty_Notes.this.setListAdapter(file_adapter);
}
@Override
protected void onListItemClick(ListView lv, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(lv, v, position, id);
Option o = file_adapter.getItem(position);
if(o.getData().equalsIgnoreCase("folder")||o.getData().equalsIgnoreCase("parent directory")){
currentDir = new File(o.getPath());
fill(currentDir);
}
else
{
onFileClick(o);
}
}
private void onFileClick(Option o)
{
path = o.getPath();
openPdfIntent(path);
}
private void openPdfIntent(String path) {
try {
final Intent intent = new Intent(Faculty_Notes.this, Second.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
另外,Second.class文件包含上面给出的代码
希望这能帮你好运:你没有定义任何内容,对吗?官方自述文件只告诉您在您的内部添加布局: