① 빌드 (Build)
② 실행 (에뮬레이터 실행)
1) Scroll View
- 수직(위아래) 스크롤 기능
* 스크롤뷰 : 하나의 위젯만 삽입 가능
스크롤뷰 안에 Liner Layout 삽입 후 그안에 위젯 삽입하는 형식으로 사용함
ScrollView - xml 코드 / orientaion = vertical
1 2 3 4 5 6 7 8 9 10 11 12 13 | <ScrollView> <LinearLayout android:orientation="vertical"> <Button/> </LinerLayout> </ScrollView> | cs |
2) Button Click Event?
인터넷에 나와있는 예제를 이용해서 버튼 클릭시 텍스트 박스에 숫자가 증가하게 하는 기능을 따라해봤다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity { private int iCount = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Button btnGo = (Button) findViewById(R.id.btnGo); final TextView txtCnt = (TextView) findViewById(R.id.txtCount); btnGo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { txtCnt.setText(++iCount+""); } }); } } | cs |
(http://kamang-it.tistory.com/entry/Android-03xml%EA%B3%BC-java%EC%9D%98-%EC%97%B0%EA%B2%B0-%EA%B0%84%EB%8B%A8%ED%95%9C-%EC%9D%B4%EB%B2%A4%ED%8A%B8)
3) final
static final = 상수 = 절대 변하지 않는 값 (ex. 원주율, 1년=365일)
= 객체마다 불변의 값을 가지고 있음
= 값이 공통으로 정의되어 변경해서는 안되는 상수
* final 변수 값을 바꾸려 하면 컴파일 에러가 남
4) 단축키
https://developer.android.com/studio/intro/keyboard-shortcuts
* Shift + F6 = 이름 바꾸기 (연결된 이름까지 같이 바꿔줌)
5) 이벤트 처리
(출처 : http://recipes4dev.tistory.com/55)
① 여러개 이벤트 처리해야 할 경우 아래 이벤트를 각각 버튼별로 만들어줘야함
1 2 3 4 5 6 7 8 9 10 11 12 | // 버튼 클릭 이벤트 // Red Button Click Button btnRed = (Button) findViewById(R.id.btnRed); btnRed.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View view) { // 실행할 함수 txtView.setText("Click Red Buton"); txtView.setBackgroundColor(Color.RED); } }); | cs |
② 하나만 만들어놓고 밑에서 정의 해주면됨
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 | Button.OnClickListener onClickListener = new Button.OnClickListener() { @Override public void onClick(View view) { TextView txtView = (TextView) findViewById(R.id.txtViewColor); switch (view.getId()) { case R.id.btnRed : txtView.setText("Click Red Button"); txtView.setBackgroundColor(Color.RED); break; case R.id.btnBlue : txtView.setText("Click Blue Button"); txtView.setBackgroundColor(Color.BLUE); break; case R.id.btnGreen : txtView.setText("Click Green Button"); txtView.setBackgroundColor(Color.GREEN); break; } } }; Button btnRed = (Button) findViewById(R.id.btnRed); Button btnBlue = (Button) findViewById(R.id.btnBlue); Button btnGreen = (Button) findViewById(R.id.btnGreen); btnRed.setOnClickListener(onClickListener); btnBlue.setOnClickListener(onClickListener); btnGreen.setOnClickListener(onClickListener); | cs |
참조사이트 :
https://developer.android.com/studio/intro/?hl=ko (Adroid Studio - User Guide)
http://redmuffler.tistory.com/425
http://ohjiyeondesign.tistory.com/88
https://kairo96.gitbooks.io/android/content/ch0.1.html
http://ankyu.entersoft.kr/board_Lecture/lecture_list.asp?gubun_type=android
https://medium.com/android-develop-android