我在寫一個GCM應用程序。 我無法將收到的消息設置爲文本視圖。無法使用TextView
檢查下面的代碼:
public class GcmMessageHandler extends IntentService {
String mes;
private Handler handler;
public GcmMessageHandler() {
super("GcmMessageHandler");
}
@Override
public void onCreate() {
super.onCreate();
handler = new Handler();
}
@Override
public void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
mes = extras.getString("title");
showMsg();
Log.i("GCM", "Received : (" +messageType+") "+extras.getString("title"));
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
public void showMsg(){
handler.post(new Runnable() {
public void run() {
TextView textview = (TextView)findViewById(R.id.getMsg);
textview.setText(mes);
}
});
}
}
(錯誤消息:該方法findViewById(INT)是未定義的類型新的Runnable(){})
我不認爲向textview添加文本需要處於可運行狀態。這不是錯誤,但我想我會對此發表評論。 – Onimusha