Info

hkin -^xm&icwm'm, mn&^xm, in^^imimym.^xn^tft, wnwimi

intent.setClass(eoelnfosAssistant.this, FSExplorer.class);

startActi vity(intent) ;

break;

WSik'it FSExplorcr.java, ft, S® t^c (List), IWiftl F0r/J<:

<?xml versiûn="l.0" encoding="utf-8"?>

<r,i nearLayqut xm I r.s : android="http: / /schémas . android. com/apk/ re s/android" android : orientâtion="vertical" android:layout wi.dth="fill parent" android:layout height "fill parent">

<ListView android:layout width="fi LI_parent" android:layout heigh t = " fi 11_ parent. " android:id="@+id/itemlist" /> </LinearLayout>

fô-ii/ï FSExplorer W] onCrcatc IWèÎn hTf/j<:

public void onCreate(Bundle savedlnstanceState) 1 super.onCreate(savedlnstanceState); setContentView(R.layout.files);

setTitleC&ttSWJJfc»'');

itemlist (ListView) findViewByld<R.id.itemlist); refreshListItems(path); )

^JnJWIJ rcfreshListItems()^®iX#^J^. f^i&ll K0PJ*:

private void refreshListI terns(String path) (

list = buiIdListForSimpleAdapter(path);

SimpieAdapter notes = new SimpleAdapter(this, list, R.layout.file_row, new Stringt] \ "name", "path" ,"img"|, new int|| < R.id.name,

itemlist. set.Adapter (notes) ;

item]i st.setOnltemClickListener(this);

itemlist.setSelection(0); }

i^H-'I'ttftiMJIJ buildListForSimpleAdapter(path)^lRA:fr^J^, ttWiW F/Tw:

private List<Map<String, Object>> bui IdList: For SimpleAdapter (String path) ( FilelJ files = new File(path).listFiles();

List<Map<String, Object» list = new ArrayList<Map<String, Object» (files, length) ; Map<String, Object> root = new HashMap<String, Object>(); root.put("name", "/");

root.put("img", R.drawable.file rooL); root .put. ("path", "go to root directory"); list.add(root);

Map<String, Object> pmap - new HashMap<String, Object>(); pmap.put("name", "..");

prnap. put (" img", R.drawable . f i le paranet) ; pmap.put("path", "go to paranet Directory"); list.add(pmap); for (File file : files) i

Map<St.ring, Object> map new HashMap<String, Object>();

if(file.isDirectory())(

map.put("img", R.drawable.directory);

map.put("img", R.drawable.file doc);

map. pu t: ( "name", fi 1 e . ger Name () ) ; map.put("path", file.getPath() ) ;

return lists; )

immft:

UtfMWJ H-ffi'iViWh ttJU File(path).listFiles( ) jj}}M "]' W ifcttCSCftfll A"ft kW k, Mfn{f-K List

<nmin) ¡[¿^.'WiMittro mi*, a? saw - KfoiMi4Ar-UJ£. mmm^nmrnx fl=*#i if'l-. fWJnTWiRi

©Override public void onltemClick(AdapterView<?> parent. View v, int position, long id) { Log.i(TAG, "item clicked! [" * position f "1"); if (positron == 0) ( path = "/";

refreshList1 terns(path); [else if(position == 1) ! goToParent() ; I else (

path = (String) list.get(pasi tion)-get("path");

File file - new File(path);

if (file.isDirectory())

refreshListlterris (path) ;

else

Toast .makeText (FSExplp.rer .this, getString(R.string.is file),

0 0

Post a comment