Possible Duplicate:
Android: Toast won t delay on spinner
I want to delay the toast "Your message "message" is sent to "contact" to appear according to the delay the user chose in the spinner. The following codes has errors (pos), here s my code:
Handler handler = new Handler();
spinnerTimeDelay = (Spinner) findViewById(R.id.spinner_delay);
spinnerTimeDelay.setOnItemSelectedListener(this);
ArrayAdapter<String> aa=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,items);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerTimeDelay.setAdapter(aa);
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);
}
public void onNothingSelected(AdapterView<?> parent) {
return;
}
btnSend.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String phoneNo = editTextRecipient.getText().toString();
String message = editTextNewMessage.getText().toString();
boolean split = false;
final Toast toast = Toast.makeText(getBaseContext(),
"Your message " + """ + message + """ + " is sent to " +"""+ phoneNo+""",
Toast.LENGTH_SHORT);1
Runnable showToastRunnable = new Runnable() {
public void run() {
toast.show();
}
};
if (phoneNo.length()>0 && message.length()>0) {
if (pos == 0) {
handler.postDelayed(showToastRunnable, 0);
}
else if (pos == 1) {
handler.postDelayed(showToastRunnable, 15000);
}
else if (pos == 2) {
handler.postDelayed(showToastRunnable, 30000);
}
else if (pos == 3) {
handler.postDelayed(showToastRunnable, 60000);
}
}
else
Toast.makeText(getBaseContext(),
"Please enter both phone number and message.",
Toast.LENGTH_SHORT).show();
}
});
}
我应如何宣布这一说法?