tags:

views:

73

answers:

1

Is it somehow possible that instead of:

Button btnNextWord = (Button) this.findViewById(R.id.btnNextWord);

Eclipse automatically generates for me something like:

Button btnNextWord = this.btnNextWord;
or
Button btnNextWord = R.id.getBtnNextWord(this);

??

A: 

No, because what you're doing in requesting a reference to a child element that has a certain name and Eclipse isn't actually loading in the layout xml so it can't know what is in it.

CaseyB
Well, it's obviously loading layout xml to parse elements (in order to generate R.id.lblNextWord)... why could it parse type of element and wrap it in R class?
kape123
It can't cast the View to the right type and return it because then you would need to have method signatures that differed only by return type, (i.e. public Button findById(int id) and public CheckBox findById(int id)) which is not allowed in a statically typed language like Java. Also it is not possible to dynamically add methods to the Android API's based on the names that you give your widgets.These things would be possible in a functional scripting language that is dynamically typed, like Lua or Python.
CaseyB
"Well, it's obviously loading layout xml to parse elements". No, it isn't. It is reading in the source to the R.java class in your gen/ directory. That file is generated by the aapt tool, IIRC.
CommonsWare
:)I never said it needs to have unique method name - it can have get<uniqueControlId>(context) with typed return value (it can be property).In nutshell, I don't mind that much about way it's implemented, just I don't wish to _findViewById_ on every 5 lines, and see no reason why those controls can't be exposed as typed properties...So, anyone else - any support for this in Android/Eclipse, or I need to write add-in for Eclipse/extend framework?
kape123
No, no support for this in Android or Eclipse.
CaseyB