android - Extends Fragment instead ListFragment -
i using listfragment need use fragment display listview. how use fragment instead of listfragment plz me. give me explanation 1 better use. want use extends fragment instead * extends listfragment*
import java.util.arraylist; import android.app.activity; import android.app.listfragment; import android.os.asynctask; import android.os.bundle; import android.view.view; import android.widget.listview; import android.widget.toast; public class countrylistfragment extends listfragment{ arraylist<video> videos; activity mactivity; /** list of countries displayed in listfragment */ listfragmentitemclicklistener ifaceitemclicklistener; /** interface defining callback method */ public interface listfragmentitemclicklistener { /** method invoked when item in listfragment clicked */ void onlistfragmentitemclick(int position); } /** callback function, executed when fragment attached activity */ @override public void onattach(activity activity) { super.onattach(activity); mactivity=activity; try{ /** statement ensures hosting activity implements listfragmentitemclicklistener */ ifaceitemclicklistener = (listfragmentitemclicklistener) activity; }catch(exception e){ toast.maketext(activity.getbasecontext(), "exception",toast.length_short).show(); } } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); new subtask().execute(); } private class subtask extends asynctask<void, void, arraylist<video>>{ @override protected void onpreexecute() { // todo auto-generated method stub super.onpreexecute(); } @override protected arraylist<video> doinbackground(void... params) { //crearte instance http call gethttpcall getcall=new gethttpcall(); string response=null; try { response=getcall.connect(); } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); } jsonparser _parser=new jsonparser(); _parser.parsehttpjson(response); string [] item = jsonparser.num_title; int []id=jsonparser.num_id; videos=new arraylist<video>(); for(int i=0;i<item.length;i++) { video vid=new video(); vid.settitle(item[i]); vid.setid(id[i]); videos.add(vid); } return videos; } @override protected void onprogressupdate(void... values) { // todo auto-generated method stub super.onprogressupdate(values); } @override protected void onpostexecute(arraylist<video> result) { super.onpostexecute(result); binddataadapter adapter = new binddataadapter(mactivity, videos); setlistadapter(adapter); } } @override public void onlistitemclick(listview l, view v, int position, long id) { /** invokes implementation of method onlistfragmentitemclick in hosting activity */ ifaceitemclicklistener.onlistfragmentitemclick(position); } }
check out this
clone it, create project in ide , @ sample app 'testbeddslv' , how uses 'dslvfragment' , listfragment.
Comments
Post a Comment