I'm trying to make a Toast
appear as soon as the user chooses a Listview
option, but when the user chooses the option, the Acticity
is first loaded and then the Toast
appears. What I really want is the opposite.
Follow 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 first execute Toast
and then start Activity
?