java - How to use a method within a fragment? -


i'm trying write fragment has method set in textview. have following fragment:

public class detailfragment extends fragment {   @override   public view oncreateview(layoutinflater inflater, viewgroup container,       bundle savedinstancestate) {     view view = inflater.inflate(r.layout.my_fragment, container, false); //    settext("set something");     return view;   }    public void settext(string item) {     textview view = (textview) getview().findviewbyid(r.id.detailstext);     view.settext(item);   } } 

this works fine. shows textview. want edit text in textview programatically. thought i'd first start editing within fragment. i've got method should able it. when uncomment settext("set something");it gives me inflateexception: error inflating class fragment. , have no clue why.

would know how can solve this?

do way

class ... extends fragment{    private textview _mytextview;     oncreateview(...){        //inflate view         _mytextview = (textview)view.findviewbyid(r.id.text_view);        edittext("blablabla");    }      private void edittext(string text){        _mytextview.settext(text);    } } 

ypu have initialize ui elements in oncreateview inflate view inflating!


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -