android - 有人可以向我解释如何在我的处理程序中使用 switch(msg.what){} 吗?

标签 android handler msg

我真的不明白消息。什么?如果有人可以解释如何使用它,以便我的处理程序的 switch 语句可以分离出 TextView 中的更改,我真的很感激它,非常感谢您。

这是我的处理程序:

    mHandler = new Handler() {
        public void handleMessage(Message msg) {
            // TODO Auto-generated method stub
            super.handleMessage(msg);
            switch (msg.what){

            }
            Bundle bundle = msg.getData();
            String string = bundle.getString("outKey");
            display.setText(string);
            }

        };

这是消息的来源:

public class myThread extends Thread {
    String outString;
    Thread hello = new Thread() {
        @Override
        public void run() {
            // TODO Auto-generated method stub
            super.run();
    String P1 = "Enter Point 1.";

            Message msg1 = Message.obtain();
            Bundle bundle1 = new Bundle();

            bundle1.putString("P1Key", P1);
            msg1.setData(bundle1);
            msg1.what = POINTONE;
            mHandler.sendMessage(msg1);
            synchronized(Lock){
                try {
                    Lock.wait();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
         outString = call.getCoords();

            }
            Message msg = Message.obtain();
            Bundle bundle = new Bundle();

            bundle.putString("outKey", outString);
            msg.setData(bundle);
            mHandler.sendMessage(msg);

        }

    };

最佳答案

msg.what 用于中继一个简单的 int,而不必担心将其添加到消息中。您的 switch 语句可以将 msg.what 视为整数

关于android - 有人可以向我解释如何在我的处理程序中使用 switch(msg.what){} 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17479335/

相关文章:

android - "None of the following functions can be called with the arguments supplied"带燃料 HTTP

android - 使用 Hilt 注入(inject) viewModel 时不调用 init

android延迟使用处理程序

java - 在java中读取.msg文件的加密附件

python - 用python解析outlook .msg文件

android - Ant 发布期间无法解析项目目标

android - 为什么创建 C++11 线程会导致致命信号?

Android线程问题,为什么当我使用工作线程时ui仍然阻塞?

go - 停止HTTP调用并使用一系列处理程序返回错误;可能吗?

powershell - 使用Powershell重命名.msg文件