实时更新toast文本值不重复弹出toast demo

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
openButton = (Button) findViewById(R.id.open);
closeButton = (Button) findViewById(R.id.close);
openButtonOne = (Button) findViewById(R.id.openOne);
openButton.setOnClickListener(this);
closeButton.setOnClickListener(this);
openButtonOne.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.open:
msg ="开启Toast";
break;
case R.id.close:
msg ="关闭Toast";
break;
case R.id.openOne:
msg="打开服务";
break;
default:
break;
}
if (mToast != null) {
mToast.setText(msg);
mToast.setDuration(Toast.LENGTH_SHORT);
} else {
mToast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
}

mToast.show();
}

你可能感兴趣的:(实时更新toast文本值不重复弹出toast demo)