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

时间:2013-07-04 23:47:15

标签: android handler msg

我真的不明白msg.what?如果有人可以解释如何使用它,那么我的处理程序的switch语句可以将文本视图中的更改分开,我真的会指出它,非常感谢你们的高级。

这是我的处理程序:

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

        };

这是msg的来源:

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

        }

    };

1 个答案:

答案 0 :(得分:1)

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