片段中的PDF查看器?

时间:2018-01-25 15:18:54

标签: java android android-fragments pdf

我已经创建了一个应用程序,其中包含片段。我的PDF查看器工作得很好但不是片段。我怎么能解决这个问题?我有资产文件和一切。编译的git中心参考,XML只是有片段的问题。谢谢你

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);

            //pdfView = getView().findViewById(R.id.pdfView);
            //pdfView.fromAsset("tenor-madness.pdf").load();
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_tab1, container, false);

    }

XMLFİLE

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="liselimanyak.practice.Tag2">

    <!-- TODO: Update blank fragment layout -->

    <com.github.barteksc.pdfviewer.PDFView
        android:id="@+id/pdfView"
        android:layout_width="match_parent"
        android:layout_centerInParent="true"
        android:layout_height="match_parent"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="tab1"
        android:layout_centerInParent="true"
        android:textSize="30dp"/>

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

您无法在findViewById()中拨打onCreate() ....在onCreateView中执行此操作(使用以下内容)...或者onViewCreated中使用view View v = inflater.inflate(R.layout.fragment_tab1, container, false; pdfView = v.findViewById(R.id.pdfView); param)

onViewCreated

...或者,如果使用@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); pdfView = view.findViewById(R.id.pdfView); pdfView.fromAsset("tenor-madness.pdf").load(); }

brew install nasm
相关问题