我在 fragment 中有一个可运行的。 runnable 旨在更新 TextView 以及使用按钮接收输入。但是程序甚至一次都没有进入runnable。
请帮忙。我究竟做错了什么。 谢谢。 代码如下。我在 runnable 中有按钮和 TextView 。
public class TodayFragment extends Fragment {
//initialisations
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//UI initialisations
Handler mHandler = new Handler();
Runnable mTicker = new Runnable() {
@Override
public void run() {
//user interface interactions and updates on screen
mHandler.postDelayed(mTicker, 1000);
mTicker.run();
}
最佳答案
似乎你想每 1 秒改变一次你的观点。如果你这么说,你也应该在你的可运行方法之外执行你的处理程序。即:
Handler mHandler = new Handler();
Runnable mTicker = new Runnable() {
@Override
public void run() {
// user interface interactions and updates on screen
// if you want to run this handler only once then delete below line
mHandler.postDelayed(mTicker, 1000);
}
};
mHandler.postDelayed(mTicker, 1000);
关于java - 可运行处理程序未在 fragment 内执行。无法启动可运行的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26314406/