我想在Android上单击ListView项目点击时阅读文本文件.. 我想创建一个Android应用程序,我在其中创建了ListView的一些字符串列表。如果我点击ListView项目,将打开一个文本文件,如何在Android Studio中执行此操作
答案 0 :(得分:0)
public void onListItemClick(ListView l, View v, int position, long id) {
您可能需要一个班级Filechooser
,您可以将意图发送到
Intent i = new Intent(this, FileChooser.class);
答案 1 :(得分:0)
你可以试试这个:
// Instanciating an array list
ArrayList<String> your_array_list = new ArrayList<String>();
//add file names
// This is the array adapter, it takes the context of the activity as a
// first parameter, the type of list view as a second parameter and your
// array as a third parameter.
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
this,
android.R.layout.simple_list_item_1,
your_array_list );
listview.setAdapter(arrayAdapter);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
String file_name = your_array_list.get(position);
File file = new File(dirPath, file_name);
//do stuff
}
});