Repository navigation
Adding @Check Annotation #389
Description
Activity
Interesting. Could you write a small code sample on what the generated code would look like ?
It seems a really great idea to me !
I think we should extend the usage of this annotation to CompoundButton and all its subclasses.
Also I would prefer a name like
@CheckedStateChangeor@CheckedChange. Until now we use listeners interfaces names to determine the annotation name :OnClickListener=>@ClickOnTouchListener=>@TouchOnItemClickListener=>@ItemClickOnCheckedChangeListenershould be@CheckedChange
Finally I think it would be nice to let users determine which parameters they really need. In this manner, the
viewand thecheckedparameters will be optional (like the @TextChange or @SeekBarProgressChange)By browsing youtube I found the Compound sound : http://www.youtube.com/watch?v=RoX9ojwca8M :)
Ah, I understand the naming scheme and of course makes sense like that.
Code sample:
XML Layout:
<CheckBox android:id="@+id/chkType1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/type1" /> <CheckBox android:id="@+id/chkType2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/type2" /> <CheckBox android:id="@+id/chkType3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/type3" /> <CheckBox android:id="@+id/chkType4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/type4" />
Activity Code:
package com.myapp; // ... @CheckedChange({R.id.chkType1, R.id.chkType2}) void checkBoxChecked(CompoundButton buttonView, boolean isChecked) { // Both parameters for convenience. } @CheckedChange(R.id.chkType3) void type3Checked(CompoundButton buttonView) { // Just the button. } @CheckedChange(R.id.chkType4) void type4Checked(boolean isChecked) { // Just the state. }
Generated code:
private void afterSetContentView_() { { View view = findViewById(com.myapp.R.chkType1); if (view!= null) { ((CompoundButton) view).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { MyActivity_.this.checkBoxChecked(buttonView, isChecked); } } ); } } { View view = findViewById(com.myapp.R.chkType2); if (view!= null) { ((CompoundButton) view).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { MyActivity_.this.checkBoxChecked(buttonView, isChecked); } } ); } } { View view = findViewById(com.myapp.R.chkType3); if (view!= null) { ((CompoundButton) view).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { MyActivity_.this.type3Checked(buttonView); } } ); } } { View view = findViewById(com.myapp.R.chkType4); if (view!= null) { ((CompoundButton) view).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { MyActivity_.this.type4Checked(isChecked); } } ); } } }
Merci ;-)
Hi Sebastian :)
The generated code seems good.
Are you interested in contributing to AndroidAnnotations ? The implementation of that feature could be a good way to take a tour on AndroidAnnotations plumbing.
Yes, I'd love to work on that.
Will do once time allows. Hope within a week or 2.Great !
What state of this feature?
Hi @luxtau,
This feature is planned for 3.0. It seems that nobody has started working on that issue.
Feel free to implement it :)
Probably, it will be easier to implement this feature after #434. So, I'm woriking
This should be documented and closed.
In a recent project I have to deal with lots CheckBoxes.
There is some special logic (e.g. disallow multi select etc) and it should be possible to add this into AA.
I'd follow to the idea of
@Click- if no-one else is working on it already.Any preferred names & methods? I'm thinking of:
The (optional)
checkedparameter might be superfluous as this is also provided through theboxobject.