如何用textview替换吐司?

时间:2016-02-03 08:50:33

标签: android google-cloud-messaging textview

我正在使用GSM应用程序。来自服务器的传入消息显示为Toast。如何将以下代码中的toast替换为textview?

public class GcmMessageHandler extends IntentService {

     String mes;
     private Handler handler;
    public GcmMessageHandler() {
        super("GcmMessageHandler");
    }

    @Override
    public void onCreate() {

        // TODO Auto-generated method stub
        super.onCreate();
        handler = new Handler();

    }
    @Override
    protected void onHandleIntent(Intent intent) {
        Bundle extras = intent.getExtras();

        GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
        // The getMessageType() intent parameter must be the intent you received
        // in your BroadcastReceiver.
        String messageType = gcm.getMessageType(intent);

       mes = extras.getString("title");
       showToast();
       Log.i("GCM", "Received : (" +messageType+")  "+extras.getString("title"));

        GcmBroadcastReceiver.completeWakefulIntent(intent);

    }

    public void showToast(){
        handler.post(new Runnable() {
            public void run() {
                Toast.makeText(getApplicationContext(),mes , Toast.LENGTH_LONG).show();
            }
         });

    }
}

1 个答案:

答案 0 :(得分:1)

您可以将TextView设置为Toasts视图,如下所示:

namespaces