Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从c2dm事件侦听器更新活动文本区域_Android - Fatal编程技术网

Android 从c2dm事件侦听器更新活动文本区域

Android 从c2dm事件侦听器更新活动文本区域,android,Android,我想在触发c2dm事件时更新布局元素(TextArea),如何从事件侦听器获取视图 事件侦听器中,两行感兴趣的内容位于消息处理、更新文本区域注释下 public class C2DMMessageReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Strin

我想在触发c2dm事件时更新布局元素(TextArea),如何从事件侦听器获取视图

事件侦听器中,两行感兴趣的内容位于消息处理、更新文本区域注释下

public class C2DMMessageReceiver extends BroadcastReceiver {
        @Override
                public void onReceive(Context context, Intent intent) {
                    String action = intent.getAction();
                    Log.w("C2DM", "Message Receiver called");
                    if ("com.google.android.c2dm.intent.RECEIVE".equals(action)) {
                        Log.w("C2DM", "Received message");
                        final String payload = intent.getStringExtra("payload");
                        Log.d("C2DM", "dmControl: payload = " + payload);

                        // Message handling, update text area
                        if(payload.equals("DataUpdate")) {
                         t=(TextView) context.findViewById(R.id.gameConsoleText); 
    t.setText("evt rcvd!");
                        }
                    }
                }
    }
此行有错误,我无法从上下文获取findViewByID

 t=(TextView) context.findViewById(R.id.gameConsoleText); 
有什么想法吗?谢谢

findViewById()只存在于活动中

但你可以用这样的方法:

LayoutInflater myInflater = LayoutInflater.from(context);
View myView = myInflater.inflate(R.layout.yourView, null);
t = (TextView) myView.findViewById(R.id.gameConsoleText);
但您可能应该提出在活动中更新UI的意图