[Android] mobile guard custom combination control
set focus
New settingactivity
Set click events for GridView entries
Call setonitemclicklistener() method of GridView object, parameter: onitemclicklistener object
Anonymous inner class implementation, override the onitemclick() method, and pass in the following parameters:
Parent is the GridView object, view is the current view object, and position is the current index
Switch judges that when setting the index of the center, it jumps to the setting center
Setting center interface
Use relative layout, right< Check@R_ 898_ 2419 @ / > on the right side of the parent control, vertically centered
set up Check@R_ 898_ 2419 @ click forbidden, Android: clickable = "false"
Set vertical center, Android: Layout_ centerVeritical=”true”
Draw a black line
Add a < view / > control with a height of 0.2dp, a black background color and a left-right margin of 5dp, which is located at the bottom of the parent control
Custom combination view
For reuse, we put these into a combined layout file
In the UI package, create a new class, settingitemview, which inherits the relativelayout of the system
Implement the three construction methods of this class, and initialize the view object in these three methods
Call the view. Inflate () method to load the layout file into the settingitemview. Parameters: context, resource file, current object, this
Click anywhere on the composite control, Check@R_ 898_ 2419 @ the control shows different states
Get three control objects, textview Check@R_ 898_ 2419@
Define method isChecked (), check whether the combination control is selected, and invoke. Check@R_ 898_ 2419 @ ischecked() method of object, return result
Define the method setchecked(), set the selected state of the composite control, and call Check@R_ 898_ 2419 @ setchecked (Boolean) method of object, parameter: Boolean
Define the method setdesc(), set the description information of the combined control, and call the settext() method of the textview object. Parameter: text
Set to turn off automatic updates
Gets the setingitemview control object
Call the setonclicklistener() method of the setingitemview object to set the click event in the overridden onclick method
Call the ischecked () method of the setingitemview object to judge whether it is selected
Call setchecked() method of setingitemview object to set status. Parameter: Boolean value
SettingActivity.java
SettingItemView.java
setting_ item_ view.xml