博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nullnullRadioButton和CheckBox示例
阅读量:7005 次
发布时间:2019-06-28

本文共 3077 字,大约阅读时间需要 10 分钟。

最近笔者几篇文章介绍了改nullnull的文章. 关联文章的地址

    main.xml如下:

    每日一道理
站在历史的海岸漫溯那一道道历史沟渠:楚大夫沉吟泽畔,九死不悔;魏武帝扬鞭东指,壮心不已;陶渊明悠然南山,饮酒采菊……他们选择了永恒,纵然谄媚诬蔑视听,也不随其流扬其波,这是执著的选择;纵然马革裹尸,魂归狼烟,也要仰天长笑,这是豪壮的选择;纵然一身清苦,终日难饱,也愿怡然自乐,躬耕陇亩,这是高雅的选择。在一番选择中,帝王将相成其盖世伟业,贤士迁客成其千古文章。

    

 

    MainActivity如下:

import android.os.Bundle;import android.app.Activity;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.CheckBox;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.TextView;import android.widget.RadioGroup.OnCheckedChangeListener;public class MainActivity extends Activity {	private RadioGroup mRadioGroup; 	private CheckBox mEatCheckBox; 	private CheckBox mSleepCheckBox; 	private CheckBox mPlayCheckBox;	private Button mConfirmButton;	private TextView mResultTextView;	private StringBuffer hobby;	private String gender="";	private String selectedResult="";	@Override	public void onCreate(Bundle savedInstanceState) {		super.onCreate(savedInstanceState);		setContentView(R.layout.main);		init();	}		private void init(){		mResultTextView = (TextView) findViewById(R.id.resultTextView);		mRadioGroup = (RadioGroup) findViewById(R.id.genderRadioGroup);		mRadioGroup.setOnCheckedChangeListener(new RadioButtonOnCheckedChangeListenerImpl());		mEatCheckBox=(CheckBox) findViewById(R.id.eatCheckBox);		mSleepCheckBox=(CheckBox) findViewById(R.id.sleepCheckBox);		mPlayCheckBox=(CheckBox) findViewById(R.id.playBox);		mConfirmButton = (Button) findViewById(R.id.confirmButton);		mConfirmButton.setOnClickListener(new ButtonOnClickListenerImpl());	}	private class ButtonOnClickListenerImpl implements OnClickListener{		@Override		public void onClick(View view) {			hobby=new StringBuffer();			selectedResult=new String();			for (int i = 0; i < mRadioGroup.getChildCount(); i++) {				RadioButton radioButton=(RadioButton) mRadioGroup.getChildAt(i);				if (radioButton.isChecked()) {					gender=radioButton.getText().toString();					break;				}			}			if (mEatCheckBox.isChecked()) {				hobby.append(" ");				hobby.append(mEatCheckBox.getText().toString());			}			if (mSleepCheckBox.isChecked()) {				hobby.append(" ");				hobby.append(mSleepCheckBox.getText().toString());			}			if (mPlayCheckBox.isChecked()) {				hobby.append(" ");				hobby.append(mPlayCheckBox.getText().toString());			}			selectedResult=gender+" "+hobby.toString();			mResultTextView.setText(selectedResult);		}			}		 private class RadioButtonOnCheckedChangeListenerImpl implements OnCheckedChangeListener{			@Override			public void onCheckedChanged(RadioGroup group, int checkedId) {				RadioButton rb=(RadioButton)findViewById(group.getCheckedRadioButtonId());				String currentSelected=rb.getText().toString();				System.out.println(""+currentSelected);			}}}

    

 

 

文章结束给大家分享下程序员的一些笑话语录: 一个合格的程序员是不会写出 诸如 “摧毁地球” 这样的程序的,他们会写一个函数叫 “摧毁行星”而把地球当一个参数传进去。

转载地址:http://gkjtl.baihongyu.com/

你可能感兴趣的文章