티스토리 뷰
1. MainActivity.java
-Button.setOnClickListener() 메서드 주의
package com.example.salgu.doitmission03answer;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
ImageView imageView01;
ImageView imageView02;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView01 = (ImageView)findViewById(R.id.imageView01);
imageView02 = (ImageView)findViewById(R.id.imageView02);
Button button01 = (Button)findViewById(R.id.button01);
button01.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
moveImageUp();
}
});
Button button02 = (Button)findViewById(R.id.button02);
button02.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
moveImageDown();
}
});
moveImageUp();
}
private void moveImageUp(){
imageView01.setImageResource(R.drawable.beach);
imageView02.setImageResource(0);
imageView01.invalidate();
imageView02.invalidate();
}
private void moveImageDown(){
imageView01.setImageResource(0);
imageView02.setImageResource(R.drawable.beach);
imageView01.invalidate();
imageView02.invalidate();
}
}
'Android' 카테고리의 다른 글
DoItMission06- EditText의 NULL값 처리 (0) | 2017.07.29 |
---|---|
DoItMission04 - SMS 입력 화면 만들고 글자수 표시하기 (0) | 2017.07.16 |
Gradle 빌드 도구 (0) | 2017.06.28 |
댓글