android - List view showing on another fragment -


i'm using view pager sliding panel inside, when panel expanded creates request of users , instantiates viewholders show them in list view, problem instantiated on wherever want, how can tell in fragment should instantiated.

here code:

@override public void onpanelanchored(view panel) {     final view cview = panel;     endpointinterface service = serviceauthgenerator.createservice(endpointinterface.class);     currentid = sharedpreferences.getint("currentid", 0);     call<list<ride>> call = service.getpassengers(currentride);     call.enqueue(new callback<list<ride>>() {          @override         public void onresponse(response<list<ride>> response, retrofit retrofit) {             if (response.issuccess() && !response.body().isempty()) {                 dialogx.dismiss();                 arraylist<string> myusersname = new arraylist<>();                 arraylist<string> myuserslastname = new arraylist<>();                 arraylist<string> myusersmapdirection = new arraylist<>();                 arraylist<integer> myusersid = new arraylist<>();                 arraylist<boolean> myusersrole = new arraylist<>();                  (int = 0; < response.body().size(); i++) {                     myusersrole.add(response.body().get(i).getrole());                     myusersname.add(response.body().get(i).getuser().getfirst_name());                     myuserslastname.add(response.body().get(i).getuser().getlast_name());                     myusersmapdirection.add(getadress(new latlng(response.body().get(i).getorigin_lat(), response.body().get(i).getorigin_lng())));                     myusersid.add(response.body().get(i).getid());                     currentname = myusersname.get(i) + " " + myuserslastname.get(i);                     mmap.addmarker(new markeroptions().snippet(getadress(new latlng(response.body().get(integer.valueof(i)).getorigin_lat(), response.body().get(integer.valueof(i)).getorigin_lng()))).position(new latlng(response.body().get(integer.valueof(i)).getorigin_lat(), response.body().get(integer.valueof(i)).getorigin_lng())).title(response.body().get(integer.valueof(i)).getuser().getfirst_name()).icon(bitmapdescriptorfactory.defaultmarker(bitmapdescriptorfactory.hue_magenta)));                 }                  listadapter useradapter = new customadapterrequest(mainmenu.this, myusersname, myuserslastname, myusersmapdirection, myusersid, myusersrole, currentride);                 listview userlistview = (listview) cview.findviewbyid(r.id.listviewuserrequest);                 userlistview.setadapter(useradapter);              }          }           @override         public void onfailure(throwable t) {             toast.maketext(getapplicationcontext(), "no", toast.length_short).show();         }     }); }     

also, here adapter code:

@override public view getview(final int position, view convertview, viewgroup parent) {     view row = convertview;     myviewholder holder = null;      if (row == null) {         layoutinflater custominflater = (layoutinflater) contexto.getsystemservice(contexto.layout_inflater_service);          row = custominflater.inflate(r.layout.custom_row_request, parent, false);         holder = new myviewholder(row);         row.settag(holder);     } else {         holder = (myviewholder) row.gettag();     }      string singlenameitem = itemname.get(position);     string singlelastnameitem = itemlastname.get(position);     string singledir = itemdirection.get(position);     integer singleid = itemids.get(position);     boolean singlerole = itemroles.get(position);      holder.tv_name.settext(singlenameitem + " " + singlelastnameitem);     holder.tv_direction.settext(singledir);     holder.im_profilepic.setimageresource(r.mipmap.profile_photo3);      return row; }  

and holder class.

class myviewholder {     textview tv_name;     textview tv_direction;     imageview im_profilepic;      myviewholder(view v) {         tv_name = (textview) v.findviewbyid(r.id.nametext);         tv_direction = (textview) v.findviewbyid(r.id.origintext);         im_profilepic = (imageview) v.findviewbyid(r.id.ivimage);     }  } 

this fragment class

public class fragment1 extends fragment {      public fragment1() {     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {          if (container == null) {             return null;         }         return (cardview) inflater.inflate(r.layout.layout1, container, false);     }      @override     public void onactivitycreated(bundle savedinstancestate) {         super.onactivitycreated(savedinstancestate);     }      public void settextdestination(string origin, string destination, long date, string estimatedtime, boolean singlerole) {         textview tv_destination = (textview) getview().findviewbyid(r.id.textdestination);         textview tv_origin = (textview) getview().findviewbyid(r.id.textorigin);         textview tv_date = (textview) getview().findviewbyid(r.id.textdatepager);         textview tv_estimatedtiem = (textview) getview().findviewbyid(r.id.estimatedtimeroute);         imageview iv_roletype = (imageview) getview().findviewbyid(r.id.imgview_roletypelayout1);         tv_destination.settext(destination);         tv_origin.settext(origin);         iv_roletype.setimageresource(singlerole ? r.mipmap.steerorange3 : r.mipmap.handorange3);         tv_estimatedtiem.settext(estimatedtime);          java.util.date date = new date(date * 1000l);         dateformat format = new simpledateformat("dd-mm-yyyy    hh:mm a");         format.settimezone(timezone.getdefault());         string formatted = format.format(date);         tv_date.settext(formatted);     } } 

i created list of fragment1 mu fragment class , added list, depending on how many items on list have number of instances get, set text function works correctly don't know how list view! thanks! :d

moved method added list view fragment instantiated.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -