文件名称:安卓控件的使用例子
文件大小:9.05MB
文件格式:RAR
更新时间:2016-12-05 10:21:23
安卓控件
安卓控件的使用 package com.example.mybutton; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.RadioGroup.OnCheckedChangeListener; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.Toast; public class MainActivity extends Activity implements OnCheckedChangeListener { private RadioButton rb1,rb2,rb3; private RadioGroup rg; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); rb1=(RadioButton)findViewById(R.id.rb1); rb2=(RadioButton)findViewById(R.id.rb2); rb3=(RadioButton)findViewById(R.id.rb3); rg=(RadioGroup)findViewById(R.id.radGrp); rg.setOnCheckedChangeListener( this); } @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if(group==rg){ String rbName=null; if(checkedId==rb1.getId()) { rbName=rb1.getText().toString(); }else if(checkedId==rb2.getId()) { rbName=rb2.getText().toString(); }else if(checkedId==rb3.getId()) { rbName=rb3.getText().toString(); } Toast.makeText(this, "选择了下标为'"+rbName+"'的单选按钮",Toast.LENGTH_LONG).show(); } } }