com.handmark.pulltorefresh.library.PullToRefreshListView cannot be cast to android.widget.ListView -
i made activity page fragment page , necessary changes fragment need got error please me out of this. have activity have 2 fragments , 1 one of two.and though list view if click on 2nd 1 display @ other side of same activity page. main functionality want do.
public class freagmentmaincategory extends fragment{ private linearlayout lllayoutmain; private fragmentactivity faactivitymain; private listview lstcategorylist; private selectcategorytask mauthtask = null; private view mservicestatusview; categorydetails maincategory; private categorylistadapter adapterlist; static final int menu_manual_refresh = 0; static final int menu_disable_scroll = 1; static final int menu_set_mode = 2; static final int menu_demo = 3; private view lstlistview; private pulltorefreshlistview mpullrefreshlistview; @suppresslint("newapi") @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { //faactivitymain = (fragmentactivity) super.getactivity(); view view = inflater.inflate(r.layout.activity_fragment_main,container, false); this.getactivity().getwindow().setsoftinputmode(windowmanager.layoutparams.soft_input_state_hidden); fontutils.setcustomfont(getactivity().findviewbyid(r.id.mainview), getactivity().getassets()); lstlistview= view.findviewbyid(r.id.lstcategoryview); mpullrefreshlistview = (pulltorefreshlistview)view.findviewbyid(r.id.lstcategory); // set listener invoked when list should refreshed. mpullrefreshlistview.setonrefreshlistener(new onrefreshlistener<listview>() { @override public void onrefresh(pulltorefreshbase<listview> refreshview) { string label = dateutils.formatdatetime(getactivity().getapplicationcontext(), system.currenttimemillis(), dateutils.format_show_time | dateutils.format_show_date | dateutils.format_abbrev_all); // update lastupdatedlabel refreshview.getloadinglayoutproxy().setlastupdatedlabel(label); // work refresh list here. new getdatatask().execute(); } }); mpullrefreshlistview.setonlastitemvisiblelistener(new onlastitemvisiblelistener() { @override public void onlastitemvisible() { } }); lstlistview=(view)view.findviewbyid(r.id.lstcategoryview); lstcategorylist = (listview)view.findviewbyid(r.id.lstcategory);//got error in line //lstcategorylist = (listview) inflater.inflate(r.layout.activity_fragment_main, container, false); lstcategorylist = mpullrefreshlistview.getrefreshableview(); registerforcontextmenu(lstcategorylist); mservicestatusview = view.findviewbyid(r.id.service_status); //txttitle=(textview) getactivity().findviewbyid(r.id.servicetext); //txttitle.settext(getactivity().getresources().getstring(r.string.title_select_category)); showprogress(true); mauthtask = new selectcategorytask(); mauthtask.execute((void) null); lstcategorylist.setonitemclicklistener(new onitemclicklistener(){ public void onitemclick(adapterview<?> parent, view v, int position,long arg3) { fragment fragment = new fragment(); bundle bundle = new bundle(); //bundle.putint(key, value); //intent subcategoryintent = new intent(getactivity().getapplication(),fragmentsubcategory.class); bundle.putstring("maincategoryid", maincategory.masterinfo.get(position-1).maincatid); bundle.putstring("maincategoryname", maincategory.masterinfo.get(position-1).maincatname); //subcategoryintent.putextra("maincategoryid", maincategory.masterinfo.get(position-1).maincatid); //subcategoryintent.putextra("maincategoryname", maincategory.masterinfo.get(position-1).maincatname); //getactivity().getapplication().startactivity(subcategoryintent); fragment.setarguments(bundle); } }); return view; } public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getactivity().getmenuinflater().inflate(r.menu.activity_service, menu); return true; } @targetapi(build.version_codes.honeycomb_mr2) private void showprogress(final boolean show) { // on honeycomb mr2 have viewpropertyanimator apis, allow // easy animations. if available, use these apis fade-in // progress spinner. if (build.version.sdk_int >= build.version_codes.honeycomb_mr2) { int shortanimtime = getresources().getinteger( android.r.integer.config_shortanimtime); mservicestatusview.setvisibility(view.visible); mservicestatusview.animate().setduration(shortanimtime) .alpha(show ? 1 : 0) .setlistener(new animatorlisteneradapter() { @override public void onanimationend(animator animation) { mservicestatusview.setvisibility(show ? view.visible : view.gone); } }); lstlistview.setvisibility(view.visible); lstlistview.animate().setduration(shortanimtime) .alpha(show ? 0 : 1) .setlistener(new animatorlisteneradapter() { @override public void onanimationend(animator animation) { lstcategorylist.setvisibility(show ? view.gone : view.visible); } }); } else { // viewpropertyanimator apis not available, show // , hide relevant ui components. mservicestatusview.setvisibility(show ? view.visible : view.gone); lstlistview.setvisibility(show ? view.gone : view.visible); } } public class getdatatask extends asynctask<void, void, boolean> { @override protected boolean doinbackground(void... params) { // simulates background job. serveraccess sa=new serveraccess(); maincategory=sa.getmaincategory(); return true; } @override protected void onpostexecute(boolean result) { if(maincategory==null){ toast.maketext(getactivity().getapplicationcontext(), getresources().getstring(r.string.error_check_network), toast.length_long).show(); lstcategorylist.setadapter(null); }else if(maincategory.code.equals("mob01")){ adapterlist=new categorylistadapter(getactivity().getapplicationcontext(), maincategory.masterinfo); lstcategorylist.setadapter(null); }else if(maincategory.code.equals("mob02")){ lstcategorylist.setadapter(null); }else{ toast.maketext(getactivity().getapplicationcontext(), getresources().getstring(r.string.error_genric_error), toast.length_long).show(); lstcategorylist.setadapter(null); } // call onrefreshcomplete when list has been refreshed. mpullrefreshlistview.onrefreshcomplete(); super.onpostexecute(result); } } public class selectcategorytask extends asynctask<void, void, boolean> { @override protected boolean doinbackground(void... params) { serveraccess sa=new serveraccess(); maincategory=sa.getmaincategory(); return true; } @override protected void onpostexecute(final boolean success) { mauthtask = null; showprogress(false); if(maincategory==null){ toast.maketext(getactivity().getapplicationcontext(), getresources().getstring(r.string.error_check_network), toast.length_long).show(); lstcategorylist.setadapter(null); }else if(maincategory.code.equals("mob01")){ adapterlist=new categorylistadapter(getactivity().getapplicationcontext(), maincategory.masterinfo); lstcategorylist.setadapter(adapterlist); }else if(maincategory.code.equals("mob02")){ lstcategorylist.setadapter(null); }else{ toast.maketext(getactivity().getapplicationcontext(), getresources().getstring(r.string.error_genric_error), toast.length_long).show(); lstcategorylist.setadapter(null); } } @override protected void oncancelled() { mauthtask = null; showprogress(false); } } class categorylistadapter extends baseadapter { list<category> mainitems; context mycontext; public categorylistadapter(context context, list<category> items) { mycontext = context; mainitems = items; } public int getcount() { return mainitems.size(); } public object getitem(int index) { return mainitems.get(index); } public long getitemid(int position) { return position; } @override public view getview(int position, view convertview, viewgroup parent ) { // todo auto-generated method stub relativelayout layout = new relativelayout(mycontext); textview tv = new textview(mycontext); tv.settext(mainitems.get(position).maincatname); tv.setgravity(gravity.left); tv.settextsize(16); tv.setpadding(20, 20, 0, 20); tv.settextcolor(mycontext.getresources().getcolor(r.color.blackcolor)); relativelayout.layoutparams lp = new relativelayout.layoutparams (layoutparams.wrap_content, layoutparams.wrap_content); lp.addrule(relativelayout.align_parent_left); layout.addview(tv,lp); return layout; } }
}
here xml code
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/mainview" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@drawable/bg_main" tools:context=".freagmentmaincategory" > <linearlayout android:id="@+id/lstcategoryview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:layout_below="@+id/serviceheaderbar" android:orientation="vertical" > <!-- pulltorefreshlistview replaces standard listview widget. --> <com.handmark.pulltorefresh.library.pulltorefreshlistview android:id="@+id/lstcategory" android:layout_width="fill_parent" android:layout_height="match_parent" android:cachecolorhint="#00000000" android:divider="#19000000" android:dividerheight="4dp" android:fadingedge="none" android:fastscrollenabled="false" android:footerdividersenabled="false" android:headerdividersenabled="false" android:smoothscrollbar="true" /> </linearlayout> <relativelayout android:id="@+id/service_status" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone" > <linearlayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:layout_centervertical="true" android:background="@drawable/progress_bg" android:orientation="vertical" android:visibility="visible" > <progressbar android:id="@+id/loadingbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margintop="10dp" /> <textview android:id="@+id/service_status_message" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginbottom="10dp" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:layout_margintop="10dp" android:gravity="center_vertical" android:tag="normal" android:text="@string/title_please_wait" android:textappearance="?android:attr/textappearancemedium" android:textcolor="@color/blackcolor" android:textsize="@dimen/mainsize" /> </linearlayout> </relativelayout>
pulltorefreshlistview
wrapper around listview
, not extend listview
, can't cast directly. can cast return value of findviewbyid
pulltorefreshlistview
, call getrefreshableview() retrieve underlaying listview
. line
lstcategorylist = (listview)view.findviewbyid(r.id.lstcategory);
should
lstcategorylist = ((pulltorefreshlistview)view.findviewbyid(r.id.lstcategory)).getrefreshableview();
android has own swipetorefreshlayout widget. sure want still use pulltorefreshlistview
?
Comments
Post a Comment