Java PDF查看器的片段?
我制作了一个包含片段的应用程序。我的PDF查看器工作得很好,但不是片段。我如何修复它?我有资产文件和所有东西。编译的git hub参考,XML只是在片段方面有问题。谢谢Java PDF查看器的片段?,java,android,android-fragments,pdf,Java,Android,Android Fragments,Pdf,我制作了一个包含片段的应用程序。我的PDF查看器工作得很好,但不是片段。我如何修复它?我有资产文件和所有东西。编译的git hub参考,XML只是在片段方面有问题。谢谢 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mParam1 = getArgume
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);
}
XML Fİ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>
您不能在
onCreate()
中调用findViewById()
…在onCreateView
中进行调用(使用以下类似的方法)…或者在onViewCreated
中进行调用(使用视图
参数)
…或者,如果使用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();
}
您能确认
pdfView
设置是否正确吗?public View onCreateView(LayoutInflater充气机、ViewGroup容器、Bundle savedInstanceState){View v=inflater.inflate(R.layout.fragment_tab1,container,false);pdfView pdfView=(pdfView)v.findViewById(R.id.pdfView);pdfView.fromAsset(“tenor madness.pdf”).load();//为此碎片返回充气器充气。充气(R.layout.fragment_tab1,容器,false);}你能在你的问题中包含fragment_tab1.xml
吗?我确定我已经添加了。@AylinGörgün我想你试图编辑我的答案,而不是你原来的问题(刚刚收到关于编辑请求的通知)
@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();
}