Exception for listview adapter when listview is missing(Fragment) -
1) activity has many fragment, fragments can switch another(whole rootview change) navigation drawer.
2) have listview in fragment update using simple adapter.
3) if switch fragment while listview still loading. -an error occur.
may know how make exception this??
i extend simple adapter listview
listadapter adapter = new extendedsimpleadapter( getactivity(), news_list, r.layout.news_item, new string[]{"news", "datetime", "desc","day"}, new int[]{r.id.news, r.id.new_time, r.id.desc,r.id.day}); setlistadapter(adapter);
this custom adapter :
public class extendedsimpleadapter extends simpleadapter{ context context2; public extendedsimpleadapter(context context, list<? extends map<string, string>> data, int resource, string[] from, int[] to){ super(context, data, resource, from, to); context2=context; } public view getview(int position, view convertview, viewgroup parent){ // here let simpleadapter built view normally. view v = super.getview(position, convertview, parent); // reference picasso imageview img = (imageview) v.gettag(); textview txt = (textview) v.findviewbyid(r.id.state); if(img == null){ img = (imageview) v.findviewbyid(r.id.new_pic); v.settag(img); } // url data passed `map` string url = ((map<string, string>)getitem(position)).get("pic"); string type = ((map<string, string>)getitem(position)).get("type"); string state = ((map<string, string>)getitem(position)).get("state"); if (type.equals("reward")) { txt.setvisibility(view.visible); } else { txt.setvisibility(view.gone); } if(url.equals("")){ picasso.with(context2).load(r.drawable.default).into(img); } else{ picasso.with(context2) .load(url) .placeholder(r.drawable.default) .resize(100, 100) .centercrop() .into(img); } // return view return v; } }
the error message nullpointerexception
e/androidruntime﹕ fatal exception: main process: com.werebits.chopinkmerchant, pid: 14486 java.lang.nullpointerexception @ android.widget.simpleadapter.<init>(simpleadapter.java:85) @ com.werebits.chopinkmerchant.extendedsimpleadapter.<init>(extendedsimpleadapter.java:19) @ com.werebits.chopinkmerchant.home$placeholderfragment$4.onsuccess(home.java:488) @ com.loopj.android.http.jsonhttpresponsehandler$1$1.run(jsonhttpresponsehandler.java:128) @ android.os.handler.handlecallback(handler.java:733) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5230) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:780) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:596) @ dalvik.system.nativestart.main(native method)
is means when switch fragment when listview still loading, adapter can't find listview??
how add exception this???
Comments
Post a Comment