package com.example.s03;
import java.util.Random;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.widget.SimpleCursorAdapter.ViewBinder;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements View.OnClickListener{
Random random = new Random();
int r;
int count = 0;
Button btn_001;
TextView tv_002,tv_003;
EditText edit_msg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_001 = (Button)findViewById(R.id.btn_001);
r = random.nextInt(999) + 1;
Log.i("GAME","난수값 : " + r);
edit_msg = (EditText)findViewById(R.id.edt_msg);
tv_002 = (TextView)findViewById(R.id.tv_002);
tv_003 = (TextView)findViewById(R.id.tv_003);
btn_001.setOnClickListener(this);
edit_msg.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch (arg0.getId()){
case R.id.btn_001:
if(edit_msg.getText().toString().equals("")){
Toast.makeText(this, "숫자을 입력하세요", Toast.LENGTH_LONG).show();
} else {
count++;
int c = Integer.parseInt(edit_msg.getText().toString());
if(r > c){
//Toast.makeText(this, , Toast.LENGTH_LONG).show();
Log.i("GAME","난수값 : " + r);
tv_002.setText(edit_msg.getText().toString() + "보다 큽니다.");
tv_003.setText(tv_003.getText().toString() + " "+ edit_msg.getText().toString());
edit_msg.setText("");
} else if ( r < c) {
//Toast.makeText(this,edit_msg.getText().toString() + "보다 작습니다." , Toast.LENGTH_LONG).show();
Log.i("GAME","난수값 : " + r);
tv_002.setText(edit_msg.getText().toString() + "보다 작습니다.");
tv_003.setText(tv_003.getText().toString() + " "+ edit_msg.getText().toString());
edit_msg.setText("");
} else {
//Toast.makeText(this,Integer.toString(r) + "정답입니다." , Toast.LENGTH_LONG).show();
Log.i("GAME","난수값 : " + r);
tv_002.setText("정답입니다." + r + " " + count );
tv_003.setText("");
r = random.nextInt(999) + 1;
count = 0;
edit_msg.setText("");
}
}
break;
}
}
}
'이전것 > 개발' 카테고리의 다른 글
android -> webView (0) | 2016.07.07 |
---|---|
android -> LifeCycle (0) | 2016.07.07 |
android -> Event Case (0) | 2016.07.07 |
android -> Event (0) | 2016.07.07 |
https://play-entry.org/tt#!/basic/solve (0) | 2016.07.06 |