获得微调器值并延迟它

时间:2011-10-28 05:37:24

标签: android sms delay

有没有办法让我可以在微调器中获取用户选择的时间延迟并设置函数,以便我可以延迟消息?何我可以延迟消息呢?这是微调器的代码:

// 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;
        }

我可以延迟发送短信吗?

1 个答案:

答案 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);
         }