반응형
나의 첫번째 안드로이드 프로그래밍
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button1"
android:text="@string/strBtn1"
></Button>
</LinearLayout>

<resources>
<string name="app_name">BaseApp</string>
<string name="strBtn1">버튼입니다</string>
</resources>
여기에 버튼을 클릭하면 화면 하단에 "버튼을 클릭했어요"라는 메세지가 나타나도록
자바 코드를 추가하였다.
package com.example.baseapp;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 버튼을 클릭했을 때 작동할 코드를 이 부분에 삽입
Toast.makeText(getApplicationContext(),"버튼을 클릭했어요",
Toast.LENGTH_SHORT).show();
}
});
}
}


안드로이드 프로그래밍 공부와 별개로.... 이래서 개발자들은 네이버 블로그를 안쓰고
티스토리를 사용하는지 조금씩 알 것 같다.
소스코드 붙여넣었을 때 비교가 안될만큼 너무 깔끔하다.
스터디 정리용으로 네이버 블로그보다 티스토리가 짱이다~!!^^
반응형