GUI Components

advertisement
GUI Components
Model—View—Controller

The Model—View—Controller architecture is widely used to
help deal with GUI applications.

Model
–

View
–

The view is what the user sees. This is the visible interface.
Controller
–
2
The model contains classes that represent the data used by the
application. This will also include methods for manipulating and
computing with that data.
The controller contains code that is executed in response to user
actions and some other external events.
Radio Button

xml file
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text=“radiobutton" />
……
</RadioGroup>
3
Radio Button

.java file
1.
Find the RadioGroup using the method
findViewById
2.
Create a class implements the interface
RadioGroup.onCheckedChangeListener
Implement onCheckedChanged method
Bind the listener class to the RadioGroup using the
method setOnCheckedChangeListener
Find the checked RadioButton ID using the
method
radiogroupname.getCheckedRadioButtonId();
3.
4.
5.
4
Check Box

xml file
<CheckBox
android:id="@+id/checkbox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/checkbox1"
/>
5
Check Box

.java file
1.
Find the CheckBox using the method
findViewById
2.
Create a class implements the interface
CompoundButton.onCheckedChangeListener
Implement onCheckedChanged method
Bind the listener class to the CheckBox using the
method setOnCheckedChangeListener
To check whether the CheckBox is checked using
the method isChecked();
3.
4.
5.
6
Seek Bar

xml file
<SeekBar
android:id="@+id/seekBar1"
android:layout_width=“fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:max="44"
android:progress="29"
/>
7
Seek Bar

.java file
1.
Find the SeekBar using the method
findViewById
2.
Create a class implements the interface
SeekBar.onSeekBarChangeListener
Implement onProgressChanged method
Bind the listener class to the SeekBar using the
method setOnSeekBarChangeListener
To check the current progress of the SeekBar using
the method getProgress();
3.
4.
5.
8
Download