开发者

android onCreate confusion

Every example I find for any code makes use of onCreate(). For many of the classes I am writing for a program, I had to pass in the initial Activity as the classes required access to what is currently on display (EditText, Button, etc). I had attempted to make each class extend Activity but this typically resulted in run-time exceptions and failures. Currently, each class that requires input from the related View must make use of "parentactivity".findViewByID(...).getData().

Is this the proper way to request data from a View? Should I create respective View objects (EditText, Button, etc) and attach those to the loaded views, then request data from there?

On what I perceive to be a related issue, I had attempted to create a RelativeRadioGroup of ToggleButtons (ToggleButtons in a RelativeLayout in a RadioGroup), only to find that the android:onClick attribute for them is not calling 开发者_如何学Gothe available method. I have the method in the primary startup class (as well as a few other classes so as to pass the data to where it is needed). While I determined it is unlikely to call the method where the data is required (where the method was originally ONLY located), I do not understand why it is not called in the main class.


With regards to the radiobutton, did you add the listener?

As for passing data from views I've taken two approaches. If I have used a stock View in the Activity I get the data and then pass only the data to where I need it. Or if its a Custom View I've added my own getData() like method to conveniently get the data in the format I need it.

Don't pass your Activity around just so you can access its View's data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜