Can I use runOnUiThread
at fragment. And how to do it in fragment?
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this,"any mesage",Toast.LENGTH_LONG).show();
}
});
try
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getActivity(),"any mesage",Toast.LENGTH_LONG).show();
}
});
Use getActivity()
instead of MainActivity.this
. Also use getApplicationContext() for the Toast.makeText()
method
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getActivity().getApplicationContext(),"any mesage",Toast.LENGTH_LONG).show();
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With