Toggle button in ANDROID - An alternative to radio button
Rabu, 19 Juni 2013
0
komentar
Toggle Button is a special button that has two states for eg :"on" and "off".It can be an alternative to Radio Buttons.
Below are some methods mentioned in this example :
setOnClickListener – Used to register a callback whenever view is clicked
setChecked() – used to mark toggle button as checked/unchecked
setTextOn() – used to display text on toggle button whenever it is CHECKED
setTextOff() – used to display text on toggle button whenever it is UnCHECKED.
Below are some methods mentioned in this example :
setOnClickListener – Used to register a callback whenever view is clicked
setChecked() – used to mark toggle button as checked/unchecked
setTextOn() – used to display text on toggle button whenever it is CHECKED
setTextOff() – used to display text on toggle button whenever it is UnCHECKED.
public class MainActivity extends Activity {
ToggleButton toggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toggle = (ToggleButton) findViewById(R.id.togglebut);
// you can set text accordingly when checked or not
toggle.setTextOn("Toggle is Checked");
toggle.setTextOff("Toggle is not Checked");
// you can set if toggle to be checked or not
toggle.setChecked(true);
toggle.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (toggle.isChecked())
{
Toast.makeText(MainActivity.this, "is checked", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(MainActivity.this, "is not checked", Toast.LENGTH_SHORT).show();
}
}
});
} }
TERIMA KASIH ATAS KUNJUNGAN SAUDARA
Judul: Toggle button in ANDROID - An alternative to radio button
Ditulis oleh Unknown
Rating Blog 5 dari 5
Semoga artikel ini bermanfaat bagi saudara. Jika ingin mengutip, baik itu sebagian atau keseluruhan dari isi artikel ini harap menyertakan link dofollow ke https://androidpopuler.blogspot.com/2013/06/toggle-button-in-android-alternative-to.html. Terima kasih sudah singgah membaca artikel ini.Ditulis oleh Unknown
Rating Blog 5 dari 5
0 komentar:
Posting Komentar