Ho un cursore che può essere tirato su e poi mostra una mappa. Posso spostare il cursore su e giù per nascondere o mostrare la mappa. Quando la mappa è davanti, posso gestire gli eventi touch su quella mappa. Ogni volta che tocco, viene avviata una AsyncTask
, che scarica alcuni dati e fa un Toast
che visualizza i dati. Anche se avvio il task sull'evento touch non viene visualizzato alcun toast, non finché non chiudo il cursore. Quando lo slider è chiuso e la mappa non è più visualizzata, appare il Toast
.
Qualche idea?
Bene avviare il task
EDIT:
public boolean onTouchEvent(MotionEvent event, MapView mapView){
if (event.getAction() == 1) {
new TestTask(this).execute();
return true;
}else{
return false;
}
}
e in onPostExecute
fare un brindisi
Toast.makeText(app.getBaseContext(),(String)data.result,
Toast.LENGTH_SHORT).show();
In new TestTask(this)
, questo è un riferimento a MapOverlay
e non a MapActivity
, quindi questo era il problema.
Per visualizzare Toast nella vostra applicazione, provate questo:
Toast.makeText(getActivity(), (String)data.result,
Toast.LENGTH_LONG).show();
Un altro esempio:
Toast.makeText(getActivity(), "This is my Toast message!",
Toast.LENGTH_LONG).show();
Possiamo definire due costanti per la durata:
int LENGTH_LONG Mostra la vista o la notifica di testo per un lungo periodo di tempo.
int LENGTH_SHORT Mostra la vista o la notifica di testo per un breve periodo di tempo.
LayoutInflater myInflater = LayoutInflater.from(this);
View view = myInflater.inflate(R.layout.your_custom_layout, null);
Toast mytoast = new Toast(this);
mytoast.setView(view);
mytoast.setDuration(Toast.LENGTH_LONG);
mytoast.show();
Per brindare in Android
Toast.makeText(MainActivity.this, "YOUR MESSAGE", LENGTH_SHORT).show();
o
Toast.makeText(MainActivity.this, "YOUR MESSAGE", LENGTH_LONG).show();
( LENGTH_SHORT e LENGTH_LONG agiscono come flag booleani - il che significa che non potete inviare il timer di brindisi in milisecondi, ma dovete usare una di queste 2 opzioni )
Puoi personalizzare il tuo tost:
LayoutInflater mInflater=LayoutInflater.from(this);
View view=mInflater.inflate(R.layout.your_layout_file,null);
Toast toast=new Toast(this);
toast.setView(view);
toast.setDuration(Toast.LENGTH_LONG);
toast.show();
O in modo generale:
Toast.makeText(context,"Your message.", Toast.LENGTH_LONG).show();