안드로이드

 

 

 

 

 

 

 

 

 

 

class MainActivity

package org.androidtown.mythread;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private static final String TAG="MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void onButton1Clicked(View v){
        Log.d(TAG, "첫번째 버튼 클릭됨 : " );

        RequestThead thead =new RequestThead();
        thead.start();

        Toast.makeText(getApplicationContext(), "스레드 시작됨", Toast.LENGTH_SHORT).show();
    }


    class RequestThead extends Thread{
        public void run(){
            for(int i=0; i<100; i++){
                println("#" + i + " : 호출됨 ");

                try{
                    Thread.sleep(500);
                }catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        public void println(String data){
            Log.d(TAG, data);
        }
    }







}

 

 

R.layout.activity_main

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="org.androidtown.mythread.MainActivity">

    <Button
        android:text="스레드시작"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/button"
        android:onClick="onButton1Clicked"
        />



</RelativeLayout>

 

 

 

 

79강

 

 

 

about author

PHRASE

Level 60  머나먼나라

큰 집이 넘어지려는 데 나무 한 개로 지탱할 수는 없다. 대세가 이미 기울어져 국가가 넘어지려는 한 사람의 힘으로 버틸 수는 없다는 것이다. -잡편

댓글 ( 4)

댓글 남기기

작성