我可以在片段中使用runOnUiThread
吗?如何在片段中做到这一点?
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this,"any mesage",Toast.LENGTH_LONG).show();
}
});
答案 0 :(得分:4)
试
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getActivity(),"any mesage",Toast.LENGTH_LONG).show();
}
});
答案 1 :(得分:4)
使用getActivity()
代替MainActivity.this
。同时对Toast.makeText()
方法
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getActivity().getApplicationContext(),"any mesage",Toast.LENGTH_LONG).show();
}
});