The next standard control is the radiobutton, within a radiogroup. //d:\android\mydemos\ex5\main.xml (to be placed in tools\demo\res\layout) ------------------------------------------ ========================================== // d:\android\mydemos\ex5\demo.java //( radiobuttons) //(to be placed in tools\demo\src\mypack\mydemo) package mypack.mydemos; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.*; public class demo extends Activity { TextView label1; RadioGroup group1; RadioButton radio1,radio2; Button button1; EditText text1; @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); group1= (RadioGroup) findViewById (R.id.group1); radio1 = (RadioButton) findViewById (R.id.radio1); radio2 = (RadioButton) findViewById (R.id.radio2); button1 = (Button) findViewById(R.id.button1); text1= (EditText) findViewById(R.id.text1); text1.setText("radio"); label1 = (TextView) findViewById(R.id.label1); label1.setText("where?"); button1.setOnClickListener(new clicker()); } // ...inner class ---follows -> class clicker implements Button.OnClickListener { public void onClick(View v) { if(v==button1) { if(radio1.isChecked()) { text1.setText("madras");} if(radio2.isChecked()) { text1.setText("bombay");} } } } // ----inner class ends here --- }
Post a Comment
0 comments:
Post a Comment