开发者

Android - accessing an element in widget

I'm using hierarchyviewer to look through a widget that I'm using. (TimePicker).

Now I can see that TimePick开发者_C百科er contains id/decrement, id/increment and id/timepicker_input.

How do I get a reference to id/timepicker_input for example?

Tried my_picker.findViewWithTag("decrement"); but that returns null.

Thanks, Tee


I don't see those IDs on the TimePicker layout

http://www.google.com/codesearch/p?hl=en#uX1GffpyOZk/core/res/res/layout/time_picker.xml

I see them on NumberPicker which is used by TimePicker

http://www.google.com/codesearch/p?hl=en#uX1GffpyOZk/core/res/res/layout/number_picker.xml

You would have to locate the appropriate NumberPicker view, then locate the NumberPickerButton view.

However you have two problems here. 1. You can't get at the IDs because they're not exposed (you'd be looking at android.R.id.decrement etc.), and 2. This will be very brittle because the internal implementation of these controls will change.

If your project will have a compatible license to Apache License, Version 2.0, what you can do is to copy all of the TimePicker and NumberPicker layouts and classes into your own project, and customize them there. This way you will have full control and it is much less likely to break with future OSes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜