简体   繁体   English

如何在使用 listview 时打开资产文件夹中存储的 pdf 文件?

[英]How to open pdf files stored in assets folder while i am using listview?

I have some list of 6 subjects,I want to load different pdf file when i click on different list items.Every list item should migrate to their respective subject pdf file ??How can this be possible by using only one activity and getting migrated to multiple pdf files by their respective item on click ??我有一些 6 个主题的列表,当我单击不同的列表项时,我想加载不同的 pdf 文件。每个列表项都应迁移到各自的主题 pdf 文件??仅使用一个活动并迁移到如何做到这一点多个 pdf 文件按各自的项目单击 ?? Can anyone help me with this ??谁能帮我这个 ?? activity.java活动.java

activity1.java活动1.java

Put this code at where you wanted to handle listview click将此代码放在您要处理列表视图单击的位置

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                Intent i = new Intent(this,PdfActivity.class); // Common activity for all
                i.putExtra("position",position); // send position to Intent
                startActivity(i);

            }
        });

and on other activity which is PDfActivity which I called , you can change name whatever you want ... do below in onCreate()以及我称之为PDfActivity其他活动,您可以随意更改名称...在onCreate()执行以下操作

    int position = 0;
        Bundle bundle = getIntent().getExtras();
                if (bundle != null) {
   position = bundle.getInt("position") // String Which are send through intent
        }



 if(position==0){
      //  view.fromAsset(<your file Name in position 0 on the list>.pdf).load();
   } else if(position==1){
   // view.fromAsset(<your file Name in position 1 on the list>.pdf).load();
   }else if(position==2){
    //view.fromAsset(<your file Name in position 2 on the list>.pdf).load();
   }else if(position==3){
    //view.fromAsset(<your file Name in position 3 on the list>.pdf).load();
   }else if(position==4){
    //view.fromAsset(<your file Name in position 4 on the list>.pdf).load();
   }

   and So on.....
   //in your on create motod do it 
   listView=findViewById(R.id.grid_View);
  UnlockAdapter adapter= new UnlockAdapter(Home.this,values);
 listView.setAdapter(adapter);
 listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Toast.makeText(Home.this, "you pressed on"+position, 
      Toast.LENGTH_SHORT).show();
        String str_pos = String.valueOf(position);
        Intent intent = new Intent(getApplicationContext(),Sub_Details.class);
        intent.putExtra("myKey", str_pos);
        startActivity(intent);
    }
});
 // here is the activty where you send your intent(Sub_Detail)

 Bundle extras = getIntent().getExtras();
  String tmp = extras.getString("myKey");
  Toast.makeText(this, "new Activity: "+tmp, Toast.LENGTH_SHORT).show();
  int tmps= Integer.parseInt(tmp);
  // now do whatever you want on that position


  if (tmps==0){
   
    pdfview.fromAsset("1.pdf").load();
  }
  if (tmps==1){
   pdfview.fromAsset("2.pdf").load();
  }
  if (tmps==2){
   pdfview.fromAsset("3.pdf").load();
  }

使用这个库打开 pdf 文件Android PdfViewer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何打开存储在res / raw或assets文件夹中的pdf? - How to open a pdf stored either in res/raw or assets folder? 如何使用数据库中存储的路径打开资产文件夹中的文件? - How to open a file in the assets folder using a path stored in the database? 如何获取 pdf 文件 uri taht 存储在 assets 文件夹中,并且正在从assetmanager 获取 InputStream。 那么如何从该输入流中获取pdf uri? - how to get pdf files uri taht is stored in assets folder and am getting InputStream from assetmanager. so how to get pdf uri from that inputstream? 如何减少在assets文件夹中使用pdf文件的android应用程序大小 - how to reduce android app size that is using pdf files in assets folder 如何从assets文件夹中打开pdf文件 - how to open pdf file from assets folder 如何从Xamarin.Android中的Assets文件夹中打开pdf - How Do I Open pdf from Assets folder in Xamarin.Android 如何打开存储在Android中Assets下的文件夹中的图像 - How to open an image that is stored in a folder under Assets in android 如何从assets文件夹在Android中打开PDF文件? - How to open PDF file in Android from the assets folder? 如何分配每个按钮以从资产文件夹打开pdf文件 - How to assign each button to open a pdf file from assets folder 如何获取存储在资产文件夹中的图像文件的最后修改日期? - How do i get the last modified date of image files stored in assets folder?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM