2011-12-17 23 views
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コンテンツが表示されます。私は2つの活動を使いたくない。しかし、私は同じ見解で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> 
` 

誰でもこの文脈で私を助けることができます。

答えて

0

あなたはインテントではなくライブラリを使用する必要があります。 オープンソースライブラリを試してくださいmuPDF

+0

しかし、コードはSVNにありません。これに対する代替アプローチはどれですか?私はpdfファイルを見ることができますが、同じアクティビティで開くことを望みます。ちょうどそのボタンの下。 –

+0

SVNにはこれと何が関係していますか?他のプログラム(例:Adobe、Aldiko)でPDFを開くには、インテントを起動してPDFを開きます。アプリケーションにPDFを直接表示する場合は、自分でレンダリングする必要があります。 – Thommy

関連する問題