//ListView的点击事件实现点击读取.pdf格式文件
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(CourseFragmentActivity.this, "点击了ListView的第"+position+"条item", Toast.LENGTH_SHORT).show();
File file = new File(Environment.getExternalStorageDirectory(),"test.pdf");
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "applicationf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(CourseFragmentActivity.this,
"No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
}
}
}
});
android 调用第三方软件打开pdf文件》 ListView点击item
最新推荐文章于 2023-03-10 18:06:38 发布