java - onPostExecute is not working in fragment activity -
i want load data website using jsoup in fragment activity , show output in textview. using asynctask load data website using jsoup after getting data website onpostexecute method in asynctask not displaying data. have tried debug , seems there problem in onpostexecute , don't know why.
here code..
mainactivity2.java
package com.example.ebad.bustudentprofile; import android.os.bundle; import android.support.v4.app.fragmentactivity; import android.support.v4.view.viewpager; import com.example.ebad.bustudentprofile.tabs.slidingtablayout; public class mainactivity2 extends fragmentactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main2); // layout manager allows user flip through pages viewpager viewpager = (viewpager) findviewbyid(r.id.viewpager); // getsupportfragmentmanager allows use interact fragments // myfragmentpageradapter return fragment based on index passed viewpager.setadapter(new myfragmentpageradapter(getsupportfragmentmanager(), mainactivity2.this)); // initialize sliding tab layout slidingtablayout slidingtablayout = (slidingtablayout) findviewbyid(r.id.sliding_tabs); // connect viewpager sliding tab layout slidingtablayout.setviewpager(viewpager); } }
myfragmentpageradapter.java
package com.example.ebad.bustudentprofile; import android.content.context; import android.support.v4.app.fragment; import android.support.v4.app.fragmentmanager; import android.support.v4.app.fragmentpageradapter; public class myfragmentpageradapter extends fragmentpageradapter { private string tabtitles[] = new string[]{"tab 1", "tab 2", "tab 3"}; private context context; public myfragmentpageradapter(fragmentmanager fm, context context) { super(fm); this.context = context; } @override public int getcount() { return 3; } // return correct fragment based on index @override public fragment getitem(int position) { if (position == 0) { return new tabfragment1(); } else if (position == 1) { return new tabfragment2(); } else if (position == 2) { return new tabfragment3(); } return null; } @override public charsequence getpagetitle(int position) { // return tab title slidingtablayout return tabtitles[position]; } }
tabfragment1.java
package com.example.ebad.bustudentprofile; import android.app.activity; import android.app.progressdialog; import android.content.context; import android.os.asynctask; import android.os.bundle; import android.support.v4.app.fragment; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.textview; import org.jsoup.jsoup; import org.jsoup.nodes.document; import java.util.hashmap; public class tabfragment1 extends fragment { progressdialog progressdialoge; textview fa, na; string urlw = "http://111.68.99.8/studentprofile/personalinfo.aspx"; hashmap<string, string> hashmap; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // todo auto-generated method stub hashmap = data.map; //hashmap = (hashmap<string, string>) getarguments().get("hashmap"); view rootview = inflater.inflate(r.layout.tab_fragment_1, container, false); activity activity = getactivity(); fa = (textview) rootview.findviewbyid(r.id.fathere); na = (textview) rootview.findviewbyid(r.id.y_name); new peea(activity,rootview).execute(); return inflater.inflate(r.layout.tab_fragment_1, container, false); } private class peea extends asynctask<void, void, void> { string father ; string son ; private context activity; private view rootview; public peea(context context, view main){ this.activity=context; this.rootview=main; } @override protected void onpreexecute() { super.onpreexecute(); progressdialoge = new progressdialog(getactivity()); progressdialoge.setmessage("getting information"); progressdialoge.show(); } @override protected void doinbackground(void... params) { try { document doce = jsoup.connect(urlw) .cookies(hashmap) .get(); father = doce.select("span[id=ctl00_body_fathername]").html(); son = doce.select("span[id=ctl00_body_name]").html(); } catch (exception e) { e.printstacktrace(); } return null; } @override protected void onpostexecute(void avoid) { super.onpreexecute(); textview wa = (textview)rootview.findviewbyid(r.id.y_name); wa.settext(son); /*fa.settext(father); na.settext(son);*/ /*fa = (textview)findviewbyid(r.id.das); fa.settext(father);*/ progressdialoge.dismiss(); } } }
tab_fragment_1.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <textview android:id="@+id/fathere" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="father name" android:textsize="25dp" /> <textview android:id="@+id/y_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="your name" android:textsize="30dp" /> </linearlayout>
if guys tell problem or how solve it, helpful me
i don't think super
class has onpreexecute
function, so
super.onpreexecute();
may causing issues. can try
super.onpostexecute();
that may fix it.
Comments
Post a Comment