Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- DB 데이터 저장
- jinja2
- 사이트 도메인
- openweathermap
- 튜토리얼
- #ifdef
- OpenCV
- #else
- DB 데이터
- #undef
- #if
- 명령어
- bootstrap4 패키지
- href
- OpenCV + Flask
- javascript
- Action
- 실시간 시계
- flask
- #ifndef
- 성능지표
- 콘솔 가상환경 # 콘솔 #가상환경
- MySQL 세팅
- PyQt5
- Django
- heroku
- bootstrap
- VS Code
- #endif
- 환경변수 설정
Archives
- Today
- Total
PROGRAMMING
기기 회전 시 데이터 저장 본문
package com.example.a2011005_3;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
public static final String PLAYER_LEVEL = "playerLevel";
public static final String PLAYER_SCORE = "playerScore";
TextView textLevel, textScore;
Button btnLevelUp, btnScoreUp;
int mLevel = 0, mScore= 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textLevel = findViewById(R.id.textLevel);
textScore = findViewById(R.id.textScore);
btnLevelUp = findViewById(R.id.button);
btnScoreUp = findViewById(R.id.button2);
btnLevelUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mLevel++;
textLevel.setText("레벨: "+mLevel);
}
});
btnScoreUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mScore++;
textScore.setText("점수: "+mScore);
}
});
if(savedInstanceState == null) {
} else {
mLevel = savedInstanceState.getInt(PLAYER_LEVEL);
mScore = savedInstanceState.getInt(PLAYER_SCORE);
textLevel.setText("레벨: "+mLevel);
textScore.setText("점수: "+mScore);
}
}
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(PLAYER_LEVEL, mLevel);
outState.putInt(PLAYER_SCORE, mScore);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textLevel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="레벨: 0" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="레벨 증가" />
<TextView
android:id="@+id/textScore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="점수: 0" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="점수 증가" />
</LinearLayout>
'Android' 카테고리의 다른 글
안드로이드 참고-1 (0) | 2020.11.15 |
---|---|
텍스트 저장, 삭제, 색변경 (0) | 2020.11.05 |
데이터 저장(이메일) & onDestroy() (0) | 2020.11.05 |
CustomListView (0) | 2020.11.04 |
ListViewEdit (0) | 2020.11.04 |
Comments