android - Can't work with findViewById -


i'm having problem findviewbyid(). whenever use in code shows me error. android studio suggest me textview dateview = null; ,

dateview = (textview)dateview.findviewbyid(r.id.dateview); 

but gives error. can me work out code.

public class operationfragment extends fragment {       public operationfragment() {         // required empty public constructor     }       @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         // inflate layout fragment         return inflater.inflate(r.layout.fragment_operation, container, false);     }      public void oncreate (bundle savedinstabcestate){         super.oncreate(savedinstabcestate);         calendar c = calendar.getinstance();         simpledateformat dd = new simpledateformat("dd-mm-yyyy");         simpledateformat dt = new simpledateformat("hh:mm a");         string formatteddate = dd.format(c.gettime());         string formattedtime = dt.format(c.gettime());         textview dateview;         textview timeview;         system.out.println(formattedtime);         system.out.println(formatteddate);         dateview = (textview)findviewbyid(r.id.dateview);         dateview.settext(formatteddate);         timeview = (textview)findviewbyid(r.id.timeview);         timeview.settext(formattedtime);     } } 

as working fragment suggest way :

inside oncreateview :

textview timeview; view rootview = inflater.inflate(r.layout.fragment_operation, container, false);  timeview = (textview)rootview.findviewbyid(r.id.timeview); timeview.settext("anik rahman"); return rootview; 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -