java - How to download a file to a certain location with OnItemClickListener -
i'm trying download file @ url getting url textview.
i've set onitemclicklistener listview (it contains textview objects), when run app, click on url in listview, nothing happens. think problem lies in getalbumstoragedir() method. i'm not sure string should passed method. albumname? i've read android developer tutorial method, still confused. in case problem lies in other method, i've included both:
here's code onitemclick() method:
@override public void onitemclick(adapterview<?> adapterview, view view, int i, long l) { textview temp = (textview) view; if (isexternalstoragewritable() == true) { try { org.apache.commons.io.fileutils.copyurltofile(new url(temp.tostring()), getalbumstoragedir("download")); } catch (malformedurlexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } } here getalbumstoragedir() method:
public file getalbumstoragedir(string albumname) { // directory user's public music directory. file file = new file(environment.getexternalstoragepublicdirectory( environment.directory_music), albumname); if (!file.mkdirs()) { log.e("searchactivity", "directory not created"); } return file; } thank you.
within listener's try/catch, i'm not entirely sure
temp.tostring() is going provide you, if it's text of textview want, try
temp.gettext() instead.
Comments
Post a Comment