package com.appli.gui;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.os.Environment;
import android.widget.ArrayAdapter;
import android.widget.ListView;


import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;

import com.appli.patoche.R;


public class files_notepad_activity extends Activity {
 
	  ListView lisView1;
	  private File file;
	  private List<String> myList = new ArrayList<String>();   
	
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview_files_notepad);
        
        lisView1 = (ListView)findViewById(R.id.listView1); 

        String root_sd = Environment.getExternalStorageDirectory().toString();
        file = new File( root_sd  ) ;       
        File liste[] = file.listFiles();

        for( int i=0; i< liste.length; i++)
        {
        	if(liste[i].isFile())
        	{
        		myList.add( liste[i].getName() );
        	}	
        }

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, myList);
        
        lisView1.setAdapter(adapter);
        lisView1.setOnItemClickListener(new ListClickHandler());
        
    }
    
    public class ListClickHandler implements OnItemClickListener{
    	 
        @Override
        public void onItemClick(AdapterView<?> adapter, View view, int position, long arg3)
        {
             Intent data = new Intent();
             data.putExtra("valeur_retour", myList.get(position));
             // Activity finished ok, return the data
             setResult(RESULT_OK, data);
             finish();
        	 
             
        }
         
    }
    
}
