package com.example.administrator.myapplication;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.TextView;import android.widget.Toast;public class MainActivity extends AppCompatActivity { ////先定义文本和按钮 TextView tv_num,tv_sz; Button bt_ck; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //赋值 tv_sz=(TextView) findViewById(R.id.editText); bt_ck=(Button)findViewById(R.id.button); //按钮点击响应事件 bt_ck.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v){ int i=0; int x=8; //显示消息框 if(i<10){ if(x>Integer.parseInt(tv_num.getText().toString())){ Toast.makeText(MainActivity.this,"您输入的数字小了",Toast.LENGTH_LONG).show(); i++; } if(x<Integer.parseInt(tv_num.getText().toString())){ Toast.makeText(MainActivity.this,"您输入的数字大了",Toast.LENGTH_LONG).show(); i++; } if(x==Integer.parseInt(tv_num.getText().toString())){ Toast.makeText(MainActivity.this,"您猜对了",Toast.LENGTH_LONG).show(); } } else { Toast.makeText(MainActivity.this,"您猜测次数过多",Toast.LENGTH_LONG).show(); } } }); }}
添加回答
举报
0/150
提交
取消