android - Getting java.io.FileNotFoundException -
i have 4 file in subfolder in assets folder. have written code
@override public view getview(final int position, view convertview, viewgroup parent) { if (convertview == null){ convertview = layoutinflater.from(context).inflate(r.layout.item_list, parent, false); } final textview textview1 = (textview) convertview.findviewbyid(r.id.textview1); final textview textview2 = (textview) convertview.findviewbyid(r.id.textview2); final button show = (button) convertview.findviewbyid(r.id.show1); final button hide = (button) convertview.findviewbyid(r.id.hide1); textview1.settext(data[position]); show.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { show.setvisibility(view.invisible); hide.setvisibility(view.visible); try{ resources resources = getresources(); assetmanager assetmanager = resources.getassets(); string filelist[] = assetmanager.list("latest_trials"); if (filelist != null){ (int = 0; < filelist.length; i++){ log.v("files", filelist[i]); } } inputstream inputstream; try{ inputstream = assetmanager.open(filelist[position]); byte[] buffer = new byte[inputstream.available()]; inputstream.read(buffer); string value = new string(buffer); textview2.setmaxlines(integer.max_value); textview2.setvisibility(view.visible); textview2.settext(value); }catch (ioexception e){ e.printstacktrace(); } }catch (ioexception e){ e.printstacktrace(); } } });
all files listing , want show content of file in textview in listview not reading files , showing filenotfoundexception. please 1 help..
once getview on position value become last value. if click point last value. tag position button settag()
, in onclick gettag()
just debug , check, last value of filelist[]
.
do this-
show.settag(position) show.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { int pos = integer.parseint(v.gettag());