Supplying text from fragment to custom TextView

前端 未结 1 1605
[愿得一人]
[愿得一人] 2021-01-28 02:55

How do I set up a constructor in a custom TextView to be able to pass text from a fragment?

In other words, I\'m confused how to send text from my fragment (Fragment1) t

相关标签:
1条回答
  • 2021-01-28 03:34

    You are extending a TextView anyway. As A--C mentioned, you can use getText(), as well as setText() to get and set the text.

    In your context, I am not sure if it is a good idea to use TextView to implement your custom view/widget. View might be a better starting point, as TextView carries all kind of stuff around for formatting, icon/drawable display, click/button logic etc.

    You need to define the standard constructors if you want to be able to have the system instantiate/inflate your components from an XML layout. Then you can use standard getters/setters for your data, same way as all other controls do it.

    If you instantiate your widget/view yourself (in your code), you are free to define whatever constructors you want to (I believe).

    0 讨论(0)
提交回复
热议问题