+1 também faço por meio de callback
2017-11-15 8:47 GMT-02:00 Willian do Amor <willsazon@gmail.com>:
Na verdade o que eu faço é usar callback. Assim eu faço a interface de callback me dar o retorno e executo o método de acordo com o retorno.--Em 14/11/2017 20:19, "Daniel Vitsaus" <danielvitsaus@gmail.com> escreveu:Pessoal, eu preciso usar um método de uma fragment dentro de uma activity, mas eu não consigo passar uma referencia para essa activity. Alguem pode me ajudar?--
A ideia é essa:
public class MinhaFragment extends Fragment{
...
@Override
public void onClick(View view) {
if (view.getId() == R.id.fab) {
Intent intent = new Intent(this.getContext(), MinhaActivity.class);
startActivity(intent);
}
}
public void showMessage(String message) {
Snackbar snackbar = Snackbar.make(this.getView(), message, Snackbar.LENGTH_LONG);
snackbar.show();
}
...
}
public class MinhaActivity extends Activity{
...
@Override
public void onClick(View view) {
//chamar o metodo do fragment aqui por exemplo
minhaFragment.showMessage("Teste" );
}
...
}
Qualquer ajuda é bem vinda.
Desde já agradeço.
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com .
For more options, visit https://groups.google.com/d/optout .
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com .
For more options, visit https://groups.google.com/d/optout .
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
0 comentários:
Postar um comentário