티스토리 뷰

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();
}
}


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/12   »
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
글 보관함