android - Updating json url for Flickr api -
i using flickr api , trying change tag on original url , search based on however, reason cannot access new url, can give guidance. error getting networkonmainthreadexception:, tried move portion of code calling search.addtextchangedlistener doinbackground resulted in error.
public class getdata extends asynctask<void, void, void> { string url = "https://api.flickr.com/services/feeds/photos_public.gne?tags=kitten&format=json&nojsoncallback=1"; @override protected void onpostexecute(void result) { super.onpostexecute(result); if (dialog.isshowing()) { dialog.dismiss(); } final arraylist<flickrmodel> pomlist = new arraylist<>(); pomlist.addall(flickrlist); search.addtextchangedlistener(new textwatcher() { @override public void beforetextchanged(charsequence s, int start, int count, int after) { } @override public void ontextchanged(charsequence s, int start, int before, int count) { string tags = url.replace("kitten", s.tostring()); string searchbar = pareser.makeservicecall(tags); if (searchbar != null) { try { jsonobject obj = new jsonobject(searchbar); jsonarray list = obj.getjsonarray("items"); (int = 0; < list.length(); i++) { jsonobject jsonobject = list.getjsonobject(i); flickrmodel model = new flickrmodel(); jsonobject media; media = jsonobject.getjsonobject("media"); model.setmedia(media.getstring("m")); string title = string.valueof(jsonobject.getstring("title")); model.settitle(title); model.setlink(jsonobject.getstring("link")); string datetaken = jsonobject.getstring("date_taken"); int index = datetaken.indexof('t'); string date = datetaken.substring(0, index); model.setdate_taken(date); // model.setdescription(jsonobject.getstring("description")); string hashtag = "#" + string.valueof(jsonobject.getstring("tags")).replace(" ", " #"); model.settags(hashtag); string author = "by:" + string.valueof(jsonobject.getstring("author")); model.setauthor(author); flickrlist.add(model); } } catch (final jsonexception e) { log.e(tag, "json parsing error: " + e.getmessage()); runonuithread(new runnable() { @override public void run() { toast.maketext(getapplicationcontext(), "json parsing error: " + e.getmessage(), toast.length_long) .show(); } }); } } else { log.e(tag, "couldn't json server."); runonuithread(new runnable() { @override public void run() { toast.maketext(getapplicationcontext(), "unable read json", toast.length_long) .show(); } }); } } @override public void aftertextchanged(editable s) { } }); // updating parsed json data listview flickradapter = new flickradapter(getapplicationcontext(), r.layout.flickr_item, flickrlist); lv.setadapter(flickradapter); }
Comments
Post a Comment