안녕하세요? Toast를 하면 글자가 나오긴 나오는데,
나오는 도중에 다른버튼을 누르면 Stop되는 기능이 없나요? ㅎㅎ
아래 코드대로 했더니 안멈추더군요 ^^
좋은 아이디어 있으신 분 계신지요?
package com.commonsware.android.messages;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MessageDemo extends Activity implements View.OnClickListener {
Button toast;
Button toaststop;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
toaststop=(Button)findViewById(R.id.toaststop);
toaststop.setOnClickListener(this);
toast=(Button)findViewById(R.id.toast);
toast.setOnClickListener(this);
}
public void onClick(View view) {
Toast mToast = Toast.makeText(this, "1번", Toast.LENGTH_SHORT);
Toast nToast = Toast.makeText(this, "2번", Toast.LENGTH_SHORT);
Toast oToast = Toast.makeText(this, "3번", Toast.LENGTH_SHORT);
Toast pToast = Toast.makeText(this, "4번", Toast.LENGTH_SHORT);
if(view==toast){
mToast.show();
nToast.show();
oToast.show();
pToast.show();
}
else if(view==toaststop){
mToast.cancel();
nToast.cancel();
oToast.cancel();
pToast.cancel();
} } }
토스트를 중간에 버튼눌러서 멈추게할 방법이 없을까요?
암튼 그래도 좋은 답변 감사합니다.^^
Toast의 구조상 Duration time이 지나가면 hide가 동작되도록 되어있어서 강제로 멈추는것은 힘들어 보입니다만 약간의 워크어라운드로 토스트가 사라지기전에 버튼을 누르면 setDuration으로 시간을 조절하여 마치 멈춘것처럼 하는것은 가능한것으로 보입니다. 실제 토스트를 이런용도로는 안써봐서 잘은 모르겠습니다만 도움이 되셨나 모르겠네요.
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MessageDemo extends Activity implements View.OnClickListener {
Button toast;
Button toaststop;
Toast mToast ;
Toast nToast ;
Toast oToast ;
Toast pToast ;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
toaststop=(Button)findViewById(R.id.toaststop);
toaststop.setOnClickListener(this);
mToast = Toast.makeText(this, "1번", Toast.LENGTH_SHORT);
nToast = Toast.makeText(this, "2번", Toast.LENGTH_SHORT);
oToast = Toast.makeText(this, "3번", Toast.LENGTH_SHORT);
pToast = Toast.makeText(this, "4번", Toast.LENGTH_SHORT);
toast=(Button)findViewById(R.id.toast);
toast.setOnClickListener(this);
}
public void onClick(View view) {
if(view.getId()==R.id.toast){
mToast.show();
nToast.show();
oToast.show();
pToast.show();
}
else if(view.getId == R.id.toaststop){
mToast.cancel();
nToast.cancel();
oToast.cancel();
pToast.cancel();
} } }
이런식으로 하라고요...;




Toast mToast = Toast.makeText(this, "1번", Toast.LENGTH_SHORT);
Toast nToast = Toast.makeText(this, "2번", Toast.LENGTH_SHORT);
Toast oToast = Toast.makeText(this, "3번", Toast.LENGTH_SHORT);
Toast pToast = Toast.makeText(this, "4번", Toast.LENGTH_SHORT);
이것을 단 한번만 실행하게끔 만들어 주시면 될겁니다.