3
I’m trying to get a Toast
appears as soon as user chooses an option from Listview
, however, when the user chooses the option, it is first loaded to Acticity
and then the Toast
, and what I really want is the opposite.
Follows the code:
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
LayoutInflater layoutInflater = getLayoutInflater();
int layout = R.layout.toast_custom;
ViewGroup viewGroup = (ViewGroup) findViewById(R.id.toast_layout_root);
view = layoutInflater.inflate(layout, viewGroup);
TextView tv_texto = (TextView) view.findViewById(R.id.texto);
TextView slogan_text = (TextView) view.findViewById(R.id.slogan);
tv_texto.setText("Aguarde...");
slogan_text.setText("Carregando " + opcoes[position]);
Toast toast = new Toast(context);
if (opcoes[position] == 1){
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(view);
toast.show();
Intent intent = new Intent(context, Eventos.class);
startActivity(intent);
}
}
How to make the first execution Toast
and then start the Activity
?
See if it helps you: http://stackoverflow.com/questions/10524836/start-activity-after-toast-message
– user28595
Thanks @Diegofelipe exactly! Thank you.
– MiguelCPJava
@diegofm writes a reply.
– Jorge B.