I am having a problem were I have:
class x that extends y
and class y that extends Fragment
I wan to be able to do things in x that for eg get a textview with ID and change the text. To do this, I must get the view but I get problems. I have tried Super.getView, and I have tried to save the view in y and access from x but it does not work.
Why is this?
edit: example code:
public x extends fragment{
}
public y extends x{
public y(){
eg TextView t = this.getView().getById(...)
which will fail as cant get the view
}
}
I would save the
TextViewas a protected var in the class that extends fragment so that you have access to it from its subclasses:Keep in mind that it will only have the myTextView assigned after
onViewCreatedis called on that fragment, but you can check if it has been defined (it's not null) before doing whatever you have to.P.S.: In the case of extending an
Activityit could be assigned inonCreatemethod by calling thefindViewByIdmethod of that activity: