java - Custom checkbox class in android -
i needed correlate checkboxes position in list view in checkboxes' onclicklistener. first solution make short custom view extended checkbox had variable (position) set in getview().
public class listcheckbox extends checkbox { private int position = -1; public listcheckbox(context context) {super(context);} public listcheckbox(context context, attributeset attrs) {super(context,attrs);} public listcheckbox(context context, attributeset attrs, int defstyleattr) {super(context,attrs,defstyleattr);} @targetapi(21) public listcheckbox(context context, attributeset attrs, int defstyleattr, int defstyleres) {super(context,attrs,defstyleattr,defstyleres);} public int getposition() { return position; } public void setposition(int position) { this.position = position; } }
it worked, except changed checkboxes' color black, , nothing did (including changing android:buttontint) change it. solution hashmap view key , integer value keeps track of checkboxes' , positions, if has less ugly solution or idea why couldn't change color of checkboxes, appreciated.
you can use method of settag() past variable view,then can use gettag() variable. not need custom checkbox.
//set tag checkbox.settag(position); //get tag int position = (int)checkbox.gettag();
Comments
Post a Comment