package com.example.radiobutton;

import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import android.view.Menu;

public class MainActivity extends Activity {
TextView tv;
RadioButton rb1, rb2;
RadioGroup rg;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
setContentView(ll);

tv = new TextView(this);
tv.setText("歡迎光臨本站,您的性別是:。");

rb1 = new RadioButton(this);
rb2 = new RadioButton(this);

rb1.setText("帥哥");
rb2.setText("美女");

rg = new RadioGroup(this);

rg.addView(rb1);
rg.addView(rb2);

rb1.setChecked(true);

ll.addView(tv);
ll.addView(rg);

rb1.setOnClickListener(new SampleClickListener());
rb2.setOnClickListener(new SampleClickListener());
}

class SampleClickListener implements OnClickListener
{
public void onClick(View v)
{
RadioButton tmp = (RadioButton) v;
tv.setText(tmp.getText() + "您好。");
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}

arrow
arrow
    文章標籤
    android radio button
    全站熱搜

    痞客興 發表在 痞客邦 留言(0) 人氣()