android : Opening a file from the list of files listed in a listview -
i working on project displays list of files directory in sd card. files have displayed .xls files. have xls reader in mobile phone , want open file clicked in listview. here code:
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen,windowmanager.layoutparams.flag_fullscreen); setrequestedorientation(activityinfo.screen_orientation_sensor_landscape); setcontentview(r.layout.activity_subjects_list); final animation myanim = animationutils.loadanimation(this, r.anim.abc_grow_fade_in_from_bottom); typeface tf = typeface.createfromasset(getassets(), "fonts/myfont.ttf"); subjectslistview = (listview) findviewbyid(r.id.subjectslistview); addsubjectbutton = (imagebutton) findviewbyid(r.id.subjectslistfabutton); adapter = new arrayadapter<string>(this,android.r.layout.simple_list_item_1, filelist); subjectslistview.setadapter(adapter); subjectslistview.setonitemclicklistener(this); //attempt connect sd card string path = environment.getexternalstoragedirectory().tostring() + "/spams excel files"; file dir = new file(path); file files[] = dir.listfiles(); for(int =0; < files.length; i++){ filelist.add(files[i].getname()); } addsubjectbutton.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { v.startanimation(myanim); toast.maketext(getapplicationcontext(), "i touched.", toast.length_short).show(); v.postdelayed(new runnable() { @override public void run() { intent goto_addsubj = new intent(subjectslistactivity.this, addsubjectactivity.class); startactivity(goto_addsubj); finish(); } }, 130); } }); } @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { textview temp = (textview) view; toast.maketext(this, temp.gettext() + " " + position, toast.length_short).show(); }
i hoping guys! please me. thank :)
what want launch xls reader intent (assuming xls reader has intent can launch with).
when item clicked, grab uri file, , launch intent.
uri uri = new uri(path); intent intent = new intent(intent.action_view); intent.setdataandtype(uri, "application/vnd.ms-excel"); try { startactivity(intent); } catch (activitynotfoundexception e) { toast.maketext(context, "no application available",toast.length_short).show(); }
Comments
Post a Comment