5-2作业中加了这句话,age_01.setText(age);,他直接退出程序了
public class MainActivity extends AppCompatActivity {
//定义全局变量
private EditText name; //姓名
private RadioGroup sex; //性别
private EditText borrowtime; //借出时间
private CheckBox history, detect, art; //复选框中的内容
private TextView age_01;
private SeekBar age_02;
private ImageView image;//图片
private TextView bookname, booktype, bookage;
private Button find;
private TextView content;
private Button next;
private SeekBarListener seekBarListener;
private int age = 18;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//绑定控件
initialize();
//添加年龄改变的监听器
age_02.setOnSeekBarChangeListener(seekBarListener);
}
private void initialize() {
name = (EditText) findViewById(R.id.name);
sex = (RadioGroup) findViewById(R.id.sex);
borrowtime = (EditText) findViewById(R.id.borrowtime);
history = (CheckBox) findViewById(R.id.history);
detect = (CheckBox) findViewById(R.id.detect);
art = (CheckBox) findViewById(R.id.art);
age_01 = (TextView) findViewById(R.id.age_01);
seekBarListener=new SeekBarListener();
age_02 = (SeekBar) findViewById(R.id.age_02);
image = (ImageView) findViewById(R.id.image);
bookname = (TextView) findViewById(R.id.bookname);
booktype = (TextView) findViewById(R.id.booktype);
bookage = (TextView) findViewById(R.id.bookage);
find = (Button) findViewById(R.id.find);
content = (TextView) findViewById(R.id.content);
next = (Button) findViewById(R.id.next);
}
class SeekBarListener implements SeekBar.OnSeekBarChangeListener {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
age=seekBar.getProgress();
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// age = seekBar.getProgress();
// Toast.makeText(MainActivity.this,"年龄:"+age,Toast.LENGTH_SHORT).show();
}
}
}
正在回答
常用于age_01.setText(传一个字符串),但也可以age_01.setText(传一个int)如果传递的是int,系统则会认为,这是从values的strings中的那个资源,而你的age又不是资源,所以就会报错了。你可以改成age_01.setText(""+age);就不会报错了。祝:学习愉快
class ButtonListener implements View.OnClickListener {
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.find:
int i=0;
i++;
if(i<=1) {
borrowtime.setText(borrowtime.getText().toString() + " 00:00:00");
}
list_get.clear();
checkDate();
if(list_get.size()!=0) {
content.setText("符合条件的书有" + (list_get.size() - 1) + "本");
}
break;
class ButtonListener implements View.OnClickListener{ @Override public void onClick(View view) { switch (view.getId()) { case R.id.find: list_get.clear(); checkDate(); break; case R.id.next: if(next.isClickable()) { if (num == list_get.size() - 1) { Toast.makeText(MainActivity.this, "已经到末端,从头开始显示", Toast.LENGTH_SHORT).show(); num = 0; showPic(num); } else { num++; showPic(num); } } break; } } }
- 参与学习 504 人
- 提交作业 1003 份
- 解答问题 1044 个
本专题是专为有Java语言基础想入坑Android开发的同学们准备的。从AndroidUI基础一直到网络,数据存储,一步到位入门Android开发。如果你会Java,那就不要犹豫了~ ~
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星