猜猜我在想什么(RadioButtonID)
来源:互联网 发布:网站数据库下载工具 编辑:程序博客网 时间:2024/04/30 20:49
猜猜我在想什么(RadioButtonID)
新建一个继承Activity类的RadioButtonIDActivity,并设置布局文件为:radiobuttonid.xml。
添加布局文件:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ageofxia"
android:textSize="22sp"/>
<RadioGroup
android:id="@+id/radiobuttonid_radiogroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/radiobuttonid_rbtn01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/twentyone"/>
<RadioButton
android:id="@+id/radiobuttonid_rbtn02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/twentytwo"/>
<RadioButton
android:id="@+id/radiobuttonid_rbtn03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/twentythree"/>
</RadioGroup>
<Button
android:id="@+id/radiobutton_btn01"
style="@android:style/Widget.Button.Inset"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/sure"
android:textSize="22sp"/>
<Button
android:id="@+id/radiobutton_btn02"
style="@android:style/Widget.Button.Inset"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/clear"
android:textSize="22sp"/>
<TextView
android:id="@+id/radiobutton_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp"/>
在代码中修改:
package lyx.feng.second;
import java.util.Random;
import lyx.feng.simpletextdemo.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
public class RadioButtonIDActivity extends Activityimplements
OnCheckedChangeListener, OnClickListener {
private TextViewtv = null;
private RadioGroupgroup = null;
private Buttonbtn01 = null;
private Buttonbtn02 = null;
private int item[] = { R.id.radiobuttonid_rbtn01,
R.id.radiobuttonid_rbtn02, R.id.radiobuttonid_rbtn03, };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.radiobuttonid);
this.tv = (TextView)super.findViewById(R.id.radiobutton_tv);
this.group = (RadioGroup)super
.findViewById(R.id.radiobuttonid_radiogroup);
this.btn01 = (Button)super.findViewById(R.id.radiobutton_btn01);
this.btn02 = (Button)super.findViewById(R.id.radiobutton_btn02);
this.group.setOnCheckedChangeListener(this);
this.btn01.setOnClickListener(this);
this.btn02.setOnClickListener(this);
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.radiobutton_btn01:
int random =new Random().nextInt(3);
RadioButton temp = (RadioButton) findViewById(this.group
.getCheckedRadioButtonId());
//没有选择就不要继续点了
if (temp ==null) {
return;
}
RadioButton temp2 = (RadioButton) findViewById(item[random]);
this.tv.setText("你选择的是:" + temp.getText() + ",答案是:"
+ temp2.getText());
break;
case R.id.radiobutton_btn02:
this.group.clearCheck();
this.tv.setText("");
break;
}
}
}
- 猜猜我在想什么(RadioButtonID)
- 猜猜我在想什么(以及动画xml的设置)
- 练习写C++代码(110)--让我猜猜你在想什么?
- 猜猜结果是什么?
- 猜猜输出什么,为什么?
- 讓我看看你的唇,猜猜你在說什麼
- 让我猜猜结局
- 56 猜猜我是谁
- 猜猜谁是我
- 猜猜谁是我
- 猜猜谁是我
- 猜猜谁是我
- python小游戏-猜猜我正在想的数字是多少?
- 趣味猜猜(一)
- 猜猜......
- 谁能确定我在想什么
- 开发2年后我在想什么
- 猜猜打印的是幅什么图片?
- [LeetCode]94. Binary Tree Inorder Traversal
- 3721: PA2014 Final Bazarek|贪心
- 开启service听话筒内容
- QVTKWidget与Qt5.5.0以后版本不兼容!
- fragment 的懒加载数据
- 猜猜我在想什么(RadioButtonID)
- 磁盘管理
- ant安装、环境变量配置及验证
- 2015年第六届蓝桥杯试题(C/C++本科B组)
- windows下gun-gcc的一些编译参数
- PageSlidingTab的改进,项目中可以直接使用。
- java.lang.OutOfMemoryError:PermGen Space错误解决方法
- C 【block本质-block内部可以一直引用的变量类型】
- okhttp的简单介绍(二)之简单封装