android - An error about listview -
i tried make file choose following below link http://www.dreamincode.net/forums/topic/190013-creating-simple-file-chooser/
however, got error "your content must have listview id attribute 'android.r.id.list' "
i have googled error , need listview tag in xml file. however, above example not have , seems working well.
although not triggering file chooser in main page, think code not have differences it. me see if there ways solve problem, please?
file_view.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"> <textview android:id="@+id/fd_text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleline="true" android:textstyle="bold" android:layout_margintop="5dip"></textview> <textview android:id="@+id/fd_text2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="10dip"></textview> </linearlayout>
filechooser.java
public class filechooser extends listactivity{ private filearrayadapter adapter; private file curdir; @override public void oncreate(bundle savedinstancestate){ super.oncreate(savedinstancestate); setcontentview(r.layout.file_view); curdir = new file("/sdcard/"); fill(curdir); } public void fill(file f){ file[] dirs = f.listfiles(); this.settitle("current dir: "+f.getname()); list<fc_option>dir = new arraylist<fc_option>(); list<fc_option>fls = new arraylist<fc_option>(); try{ (file ff: dirs){ if (ff.isdirectory()) dir.add(new fc_option(ff.getname(), "folder", ff.getabsolutepath())); else fls.add(new fc_option(ff.getname(), "file size: " + ff.length(), ff.getabsolutepath())); } }catch (exception e){ } collections.sort(dir); collections.sort(fls); dir.addall(fls); if (!f.getname().equalsignorecase("sdcard")) dir.add(0,new fc_option("..","parent directory", f.getparent())); adapter = new filearrayadapter(this, r.layout.file_view, dir); //get problems this.setlistadapter(adapter); } //@override protected void onlistitemclick(listview l, view v, int position, long id){ super.onlistitemclick(l,v,position, id); fc_option o = adapter.getitem(position); if (o.getdata().equalsignorecase("folder") || o.getdata().equalsignorecase("parent directory")){ curdir = new file(o.getpath()); fill(curdir); }else{ onfileclick(o); } } private void onfileclick(fc_option o){ toast.maketext(this,"file click"+o.getname(), toast.length_short).show(); } }
the filearrayadapter same link.
thank help
this line blame:
setcontentview(r.layout.file_view);
the file_view.xml layout each item in list, not layout of list itself. since overriding listactivity, don't have set view, removing above line do.
Comments
Post a Comment