A sentimental robot

Handler 본문

Android Studio

Handler

GOD03219 2018. 2. 5. 15:39
package com.example.i310_54.myapplication08;

import android.graphics.Color;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;

import java.util.Random;

public class MainActivity extends AppCompatActivity {

String TAG="EUNBI";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {

switch (msg.what){

case 100:
Log.d(TAG, "handleMessage: 100");
handler.sendEmptyMessageDelayed(100,500);
break;
case 200:
Log.d(TAG, "handleMessage: 200");
handler.sendEmptyMessageDelayed(200,700);
break;
}

}
};
public void f1(View view) {

handler.sendEmptyMessage(100);
}

public void f2(View view) {
handler.sendEmptyMessage(200);
}

public void f3(View view) {
handler.removeMessages(100);
}

public void f4(View view) {
handler.removeMessages(200);
}
}

 

'Android Studio' 카테고리의 다른 글

OnTouch  (0) 2018.02.06
RelativeLayout  (0) 2018.02.06
GridLayout2  (0) 2018.02.05
GridLayout  (0) 2018.02.05
배경색 자동으로 바꾸기  (0) 2018.02.01