Can't you simply use the position to retrieve the file name from the files
list?

Like:

String fileName = files.get (position);


Yuvi

-- 
YuviDroid
http://android.yuvalsharon.net

On Wed, Feb 17, 2010 at 5:03 PM, André <pha...@hotmail.com> wrote:

> Hello,
>
> I have a listview that shows files in a specified folder which works.
> But what I can't figure out is in the onListItemClick method. How can
> I get the name of the selected file in the ListView from the
> ArrayAdapter instead of the position or id?
>
> Any suggestion?
>
> public void updateFileList() {
>                File home = new File(FILE_PATH);
>                if (home.listFiles().length > 0) {
>                        for (File file : home.listFiles()) {
>                                if (accept(path, file.getName()) == true) {
>                                        files.add(file.getName());
>                                        }
>                        }
>                        ArrayAdapter<String> fileList = new
> ArrayAdapter<String>(this,
> R.layout.list_items, files);
>                        setListAdapter(fileList);
>                }
>        }
>
>        @Override
>    protected void onListItemClick(ListView l, View v, int position,
> long id) {
>                super.onListItemClick(l, v, position, id);
>        try{
>                File f = new
> File(Environment.getExternalStorageDirectory()+"/
> Folder"+"?????????????????????????");
>                FileInputStream fileIS = new FileInputStream(f);
>                BufferedReader buf = new BufferedReader(new
> InputStreamReader(fileIS));
>                String readString = new String();
>                readString = buf.readLine();
>
>                TextView tv = new TextView(this);
>                tv.setText(readString);
>                setContentView(tv);
>
>        } catch (FileNotFoundException e) {
>                e.printStackTrace();
>        } catch (IOException e){
>                e.printStackTrace();
>        }
>
>    }
>
> Cheers
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en




-- 
YuviDroid
http://android.yuvalsharon.net

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to