0
我能夠閱讀PDF文件,但我有一個問題如何看到同樣的觀點(佈局)PDF內容
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button OpenPDF = (Button) findViewById(R.id.button);
OpenPDF.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
File pdfFile = new File("/sdcard/Test.pdf");
if(pdfFile.exists())
{
Uri path = Uri.fromFile(pdfFile);
Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
pdfIntent.setDataAndType(path, "application/pdf");
pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try
{
startActivity(pdfIntent);
}
catch(ActivityNotFoundException e)
{
Toast.makeText(PDFTest.this, "No Application available to view pdf", Toast.LENGTH_LONG).show();
}
}
}
});
}
現在用的是上面的代碼,當我點擊按鈕,它帶我到另一個視圖PDF內容可見。我不想使用兩個活動。但我想看到同一視圖中的PDF內容。怎麼做。如何停止導航到下一個視圖。 我的XML文件是:
`<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button android:text="Button"
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
`
任何人都可以在這方面幫助我。
但代碼不在SVN中。任何替代方法?我能夠查看PDF文件,但希望打開相同的活動。只需在該按鈕下面。 –
SVN如何處理這個問題?您打開一個PDF後,打開一個意圖在另一個程序中打開PDF(例如Adobe,Aldiko)。如果你想直接在你的應用程序中顯示PDF,你需要自己渲染它。 – Thommy