Android mobile guard -- select SettingItemView to switch the entry status and click the item entry to jump to the page
This article introduces how to customize the control combinations in the previous article.
Whether the checkBox is selected determines whether SettingItemView is enabled.
First, create a method to determine whether checkbox is enabled.
/*** Determine whether to enable the method ** @ return returns the current SettingItemView whether the selected status is true enabled (checkBox returns true) * false disables (checkBox returns true) */public boolean isCheck () {return cb_box.isChecked ();}
Controls the control display text based on the enabled Variables
/*** @ Param isCheck whether it is used as the enabled variable. It is passed by clicking */public void setCheck (boolean isCheck) {// the current entry is selected, the cb_box selection status is also changing with (isCheck) cb_box.setChecked (isCheck (); if (isCheck) {TV _des.setText ("automatic update enabled ");} else {TV _des.setText ("auto update disabled ");}}
Next, add the entry click event:
Package com. wuyudong. mobilesafe. activity; import com. wuyudong. mobilesafe. r; import com. wuyudong. mobilesafe. view. settingItemView; import android. app. activity; import android. OS. bundle; import android. view. view; import android. view. view. onClickListener; public class SettingActivity extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setConten TView (R. layout. activity_setting); initUpdate ();} private void initUpdate () {final SettingItemView siv_update = (SettingItemView) findViewById (R. id. siv_update); siv_update.setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {// if it is selected, click, it becomes unselected // if it is not selected before, after clicking it, it becomes selected // get the previously selected status boolean check = siv_update.isCheck (); // reverse the original status, the two operations of appeal are the same as siv_update.setCheck (! Check );}});}}
In this way, when an entry is clicked, the corresponding checkbox status in the custom control also changes accordingly.