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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
package com.example.myapplication;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onButton1Clicked(View v) {
Toast.makeText(this, "확인1 버튼이 눌렸어요.", Toast.LENGTH_LONG).show();
}
public void sayHello(View v){
Toast.makeText(this,"구글로 이동합니다.",Toast.LENGTH_LONG).show();
Intent int2 = new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com"));
startActivity(int2);
}
public void onButton2Clicked(View v) {
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://m.naver.com"));
startActivity(myIntent);
}
public void onButton3Clicked(View v) {
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("tel:010-1000-1000"));
startActivity(myIntent);
}
public void giveMeACall(View v){
Intent gmac = new Intent(Intent.ACTION_VIEW, Uri.parse("tel:010-7777-7777"));
startActivity(gmac);
}
}
|
cs |
Line11 MainActivity && AppCompatActivity
MainActivity는 실행시 초기 로딩을 처리해주는 클래스이다. 자바의 main메서드와 같은의미
AppCompatActivity에서 기본적인 안드로이드의 화면을 구성하는 메서드를 제공하고
그 메서드를 재정의하여 사용한다.
Line17 setContentView
setContentView 화면을 로딩할 구성 layout 선택.
실제파일 app\res\layout\activity_main.xml로 R.layout.activity_main을 초기화면 구성 파일로 처리한다.
xml 안에 있는 여러 컴퍼넌트를 화면에 로딩하여 준다.
파일 명명 규칙에 의해 해당 xml 레이아웃을 설정하면 해당 화면이 로딩된다.
Line20 public void onButton1Clicked(View v)
android:onClick="onButton1Clicked" 에 의해 아래 메서드가 호출.
onClick ="정의된 메서드" : 클릭을 통해 해당 메서드를 호출.
Line21 Toast && makeText && context && text && LENGTH_LONG && show();
Toast : 잠깐 나타났다가 사라짐
makeText() : 객체 생성이 필요없는 객체. static 메서드
context : 현재 객체를 처리한다.
text : 화면에 나타날 내용
LENGTH_LONG : 화면에 로딩될 시간, SHORT도 있음.
Line31 Intent
Intent 참조변수 = new Intent(인텐트객체선언.호출방식, 특정 주소값처리)
Intent 참조변수 = new Intent(Intent.ACTION_VIEW, Uri.parse("주소값"));
Line17 startActivity(참조변수)
startActivity(참조변수) : 외부화면을 로딩하거나 처리할 때 활용된다.
객체명 참조변수 = (typecasting)findViewByid(R.id.아이디명);
Button btn04 = (Button) findViewById(R.id.button04);
돔객체 가져올 때 언어마다 서로 다른 것처럼 안드로이드만의 방법임
참조변수명.setOnClickListener() : 해당 객체에 클릭했을 때 내용을 인식 할 수 있는 감각객체를 할당하는 메서드
new View.onClickListener() : View 객체 하위에 클릭하는 이벤트를 인식 할 수 있는 객체를 생성
객체안의 메서드가 클릭되었을 때 수행할 내용을 기술 public void onClick(View v)
'ANDROID > 되새김질' 카테고리의 다른 글
리스너 이벤트 메서드 (0) | 2019.09.16 |
---|---|
안드로이드 복습 - 4 TableLayout (0) | 2019.09.10 |
안드로이드 복습 - 3 RelativeLayout (0) | 2019.09.05 |
안드로이드 복습 - 2 (0) | 2019.09.05 |
안드로이드 크기 단위 dp, sp, pt, px, mm, in (0) | 2019.09.05 |