- Main_Activity.java



package com.zeronine;


import com.zeronine.main.R;


import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.Toast;


public class Main_Activity extends Activity{

protected void onCreate( Bundle savedInstanceState )

{

super.onCreate( savedInstanceState );

setContentView( R.layout.activity_main );

create();

}

private void create()

{

createBtn();

}

private Button btn;

private void createBtn()

{

btn = (Button) findViewById( R.id.button1 );

btn.setOnClickListener( new View.OnClickListener() {

public void onClick(View v) {

showToast( "버튼을 눌렀다." );

}

});

}

private void showToast( String message )

{

Toast.makeText( getApplicationContext(), message, Toast.LENGTH_LONG ).show();

}

}






- activity_main.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/imageView1"
        android:layout_below="@+id/imageView1"
        android:layout_marginTop="32dp"
        android:text="버튼" />
</LinearLayout>


'Android' 카테고리의 다른 글

Android addView  (0) 2015.01.07
Android AlertDialog ( 팝업)  (0) 2015.01.07
Android Vibrator ( 핸드폰 진동 )  (0) 2015.01.07

+ Recent posts