This article implements the related methods in the custom composite control in the previous article.
checkbox is checked to determine if Settingitemview is turned on.
First, create a method to determine if the checkbox is open
/** * Determines whether to open the method *@return Returns whether the current Settingitemview is checked for true on (checkbox returns True) * false Off (checkbox returns True) */public boolean Ischeck () { return cb_box.ischecked (); }
Controls display text based on the variable that is turned on
/** * Ischeck is an open variable that is passed through during the click Process */< /span> public boolean Ischeck) { // The current entry in the process of selection, the Cb_box selected state also follows (Ischeck) changes cb_box.setchecked (Ischeck ()); if (Ischeck) {Tv_des.settext ( " Auto-Update is on "); else " Automatic Update Close "); } }
Then add the entry click event:
Packagecom.wuyudong.mobilesafe.activity;ImportCOM.WUYUDONG.MOBILESAFE.R;ImportCom.wuyudong.mobilesafe.view.SettingItemView;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener; Public classSettingactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (r.layout.activity_setting); Initupdate (); } Private voidinitupdate () {FinalSettingitemview siv_update =(Settingitemview) Findviewbyid (r.id.siv_update); Siv_update.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {//if it was previously selected, after clicking, it becomes unchecked//if previously unchecked, click to select//gets the previous selected state BooleanCheck =Siv_update.ischeck (); //reverse the original state, equivalent to the two operations of the appealSiv_update.setcheck (!check); } }); }}
This changes the corresponding checkbox state contained in the custom control when the entry is clicked.
Android Phone Defender--check Settingitemview entry status Toggle