- Main_Activity.java



package com.zeronine;


import android.app.Activity;


import android.os.Bundle;

import android.widget.Button;

import android.widget.LinearLayout;


public class Main_Activity extends Activity {

protected void onCreate( Bundle savedInstance )

{

super.onCreate( savedInstance );

setContentView( R.layout.activity_main );

create();

}

private void create()

{

createLayout();

createBtn();

}

private LinearLayout layout;

private void createLayout()

{

layout = new LinearLayout( Main_Activity.this );

layout.setOrientation( LinearLayout.VERTICAL );

setContentView( layout );

}

private Button btn;

private void createBtn()

{

btn = new Button( Main_Activity.this );

btn.setText( "버튼" );

layout.addView( btn );

}

}









'Android' 카테고리의 다른 글

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

- Main_activity.java


package com.zeronine;


import android.app.Activity;

import android.app.AlertDialog;

import android.content.DialogInterface;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;


public class Main_Activity extends Activity {

protected void onCreate( Bundle savedInstance )

{

super.onCreate( savedInstance );

setContentView( R.layout.activity_main );

create();

}

private void create()

{

createBtn();

createAlertDialog();

}

private Button btn;

private void createBtn()

{

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

btn.setOnClickListener( new View.OnClickListener() {

@Override

public void onClick(View v) {

showPopup( "질문", "나 사랑하니?" );

}

});

}

private AlertDialog.Builder builder;

private void createAlertDialog()

{

builder = new AlertDialog.Builder( Main_Activity.this );

}

private void showPopup( String titleMessage, String message )

{

builder.setTitle( titleMessage );

builder.setMessage( message );

builder.setPositiveButton( "그래", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

}

});

builder.setNeutralButton( "그런가?", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

// TODO Auto-generated method stub

}

});

builder.setNegativeButton( "아닌데?", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

// TODO Auto-generated method stub

}

});

builder.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:text="Button" />

</LinearLayout>


'Android' 카테고리의 다른 글

Android addView  (0) 2015.01.07
Android Vibrator ( 핸드폰 진동 )  (0) 2015.01.07
Android Toast  (0) 2015.01.07

- Main_activity.java



package com.zeronine;


import android.app.Activity;

import android.content.Context;

import android.os.Bundle;

import android.os.Vibrator;

import android.view.View;

import android.widget.Button;


public class Main_activity extends Activity {

protected void onCreate( Bundle savedInstanceState )

{

super.onCreate( savedInstanceState );

setContentView( R.layout.activity_main );

create();

}

private void create()

{

createBtn();

createVibrator();

}

private Button btn;

private void createBtn()

{

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

btn.setOnClickListener( new View.OnClickListener() {

@Override

public void onClick(View v) {

showVibrator( 3000 );

}

});

}

private Vibrator vibrator;

private void createVibrator()

{

vibrator = ( Vibrator ) getSystemService( Context.VIBRATOR_SERVICE );

}

private void showVibrator( int value )

{

vibrator.vibrate( value );

}

}





- 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:text="Button" />


</LinearLayout>






- AndroidManifest.xml



<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.zeronine"

    android:versionCode="1"

    android:versionName="1.0" >


    <uses-sdk

        android:minSdkVersion="8"

        android:targetSdkVersion="21" />

    

    <uses-permission android:name="android.permission.VIBRATE"></uses-permission>


    <application

        android:allowBackup="true"

        android:icon="@drawable/ic_launcher"

        android:label="@string/app_name"

        android:theme="@style/AppTheme" >

        <activity android:name="com.zeronine.Main_activity" android:label="@string/app_name">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

    </application>


</manifest>



'Android' 카테고리의 다른 글

Android addView  (0) 2015.01.07
Android AlertDialog ( 팝업)  (0) 2015.01.07
Android Toast  (0) 2015.01.07




- 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