可运行的处理程序不在片段内部执行.无法启动可运行文件 [英] Runnable Handler not executing inside fragment. Could not start a runnable

查看:98
本文介绍了可运行的处理程序不在片段内部执行.无法启动可运行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在片段中有一个可运行的对象.该runnable旨在更新文本视图以及使用按钮接收输入.但是程序甚至一次都不会进入可运行程序.

I have a runnable inside a fragment. The runnable is meant to update the textviews as well as receive input using buttons. But the program does not enter even once inside the runnable.

请帮助.我究竟做错了什么. 谢谢. 代码如下.我在runnable中有按钮和textviews.

Please help. What am I doing wrong. Thanks. The code is as follows. I have buttons and textviews inside the runnable.

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();

 }

推荐答案

尝试此更改

mTicker = new Runnable() {
        public void run() {

         //user interface interactions and updates on screen

           mHandler.postDelayed(mTicker, 1000);

        }
    };
    mTicker.run();

这篇关于可运行的处理程序不在片段内部执行.无法启动可运行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆