有没有办法让我可以在微调器中获取用户选择的时间延迟并设置函数,以便我可以延迟消息?何我可以延迟消息呢?这是微调器的代码:
// Spinner
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
if(FirstLoad){
FirstLoad = false;
return;
}
Toast.makeText(parent.getContext(), "You chose " +
parent.getItemAtPosition(pos).toString()+ " to delay", Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView<?> parent) {
return;
}
我可以延迟发送短信吗?
答案 0 :(得分:0)
使用Handler。使用postDelayed可以设置延迟时间。这是link
final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
Bundle bundle = (Bundle) msg.obj;
String strDelay= bundle.getString("delay");
// Here you can do what ever you want
}
};
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
Message message = new Message();
Bundle bun = new Bundle();
bun.putString("delay", parent.getItemAtPosition(pos).toString());
message.obj = bun;
handler.sendMessageDelayed(msg, Your_Delay_Time_in_Long);
}