如何指定android.os.Message的目标?

时间:2010-08-06 17:47:14

标签: java android message handler

如何在下面的示例中将sendMessage()的目标指定为logTextBox()?

public class Controller extends Activity {
    public Handler hLogTextBox = new Handler();
    ...
    public void listener() {
        String s = "my string";
        android.os.Message osMessage = hLogTextBox.obtainMessage();
        Bundle b = new Bundle();
        b.putString(null, s);
        osMessage.setData(b);
        hLogTextBox.sendMessage(osMessage);
    }
    ...
    public void logTextBox(String s) {
        ...
    }
    ...
}

1 个答案:

答案 0 :(得分:1)

搞定了... Controller.listener()将osMessage发送到hLogTextBox.handleMessage()

public Handler hLogTextBox = new Handler() {
    @Override
    public void handleMessage(android.os.Message osMessage) {
        ...
    }
};