android - How to refresh ListView using SwipeRefreshLayout after checked a RSS title information using AsyncTask -


this situation. have fragment listview. contain news titles downloaded rss. when user refresh fragment using swiperefreshlayout (sliding finger , down twitter app) check if exist new rss items , after download new information want refresh listview.

i download new information ok using asynctask , add avisoslist (arraylist) problem in listview.

how refresh listview new information?

this oncreateview method:

@override public view oncreateview(layoutinflater inflater, viewgroup container,         bundle savedinstancestate) {      view view = inflater.inflate(r.layout.rss_avisos_fragment, container, false);            lv = (listview) view.findviewbyid(r.id.rss_avisos_lv);     lv.setonitemclicklistener(this);      // nuevo elemento: swipe refresh layout     swiperefresh = (swiperefreshlayout) view.findviewbyid(r.id.rss_avisos_swiperefreshlayout);     swiperefresh.setonrefreshlistener(this);     swiperefresh.setcolorscheme(android.r.color.holo_blue_dark,     android.r.color.holo_orange_light,     android.r.color.holo_green_dark,     android.r.color.holo_red_light);      return view; } 

onrefresh()

@override public void onrefresh() {     // todo auto-generated method stub     dowloadtest dow = new dowloadtest();     dow.execute();       } 

dowloadestest class extends asyncttask.

    public class dowloadtest extends asynctask<string, integer, string> {         @override         protected void onpreexecute() {          };          @override         protected string doinbackground(string... params) {             // todo auto-generated method stub             buscanuevasnoticasrss();             return null;         }           private void buscanuevasnoticasrss() {             // todo auto-generated method stub  //here check rss , if necessary add new items avisoslist , execute toast.  ...             if(avisoslist.size()>=1){                 string lang = (string)  miraridioma();                 insertarnuevosavisos(avisoslist, lang);                 try {                     new thread() {                         @override                         public void run() {                             looper.prepare();                             toast.maketext(getactivity().getbasecontext(), "existen nuevos avisos.", toast.length_long).show();                                                  looper.loop();                         }                     }.start();                 } catch (exception e) {                     // todo: handle exception                     e.printstacktrace();                 }              }else{                 try {                     new thread() {                         @override                         public void run() {                             looper.prepare();                             toast.maketext(getactivity().getbasecontext(), "no hay noticias", toast.length_long).show();                             looper.loop();                         }                     }.start();                 } catch (exception e) {                     // todo: handle exception                     e.printstacktrace();                 }               }          } 

onpostexecute.

    @override     protected void onpostexecute(string result) {         // todo auto-generated method stub          // update ui here          swiperefresh.setrefreshing(false);         avisosenlistaadapter adapter = new              avisosenlistaadapter(getactivity(), avisoslist);         lv.setadapter(adapter);         return;     } 

i don't receive error listview doesn't refresh.

i have found solution me.

now thi onpostexecute code:

@override protected void onpostexecute(boolean result) {     // todo auto-generated method stub      // update avisoslist (arraylist) db     databasehelper mydb = new databasehelper(getactivity().getbasecontext());     mydb.opendatabase();     avisoslist = mydb.getallavisos(lang);     tratarfechaparapublicar(avisoslist, lang);      adapter.refresh(avisoslist);     swiperefresh.setrefreshing(false);       return; } 

and need add refresh(arraylist) method adapter.

 public void refresh(arraylist<aviso> itemsw) {         this.items = itemsw;              log.d("testing2", "avisosenlistaadapter. refresh(). actualizando adaptador");         notifydatasetchanged();     } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -