1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.example.android.apis.app;
18 
19 import com.example.android.apis.R;
20 
21 import android.app.Activity;
22 import android.widget.Button;
23 import android.os.Bundle;
24 import android.view.View;
25 import android.widget.Toast;
26 
27 /**
28  * When you push the button on this Activity, it creates a {@link Toast} object and
29  * using the Toast method.
30  * @see Toast
31  * @see Toast#makeText(android.content.Context,int,int)
32  * @see Toast#makeText(android.content.Context,java.lang.CharSequence,int)
33  * @see Toast#LENGTH_SHORT
34  * @see Toast#LENGTH_LONG
35  */
36 public class NotifyWithText extends Activity {
37     @Override
onCreate(Bundle savedInstanceState)38     protected void onCreate(Bundle savedInstanceState) {
39         super.onCreate(savedInstanceState);
40 
41         setContentView(R.layout.notify_with_text);
42 
43         Button button;
44 
45         // short notification
46         button = (Button) findViewById(R.id.short_notify);
47         button.setOnClickListener(new Button.OnClickListener() {
48             public void onClick(View v) {
49                 // Note that we create the Toast object and call the show() method
50                 // on it all on one line.  Most uses look like this, but there
51                 // are other methods on Toast that you can call to configure how
52                 // it appears.
53                 //
54                 // Note also that we use the version of makeText that takes a
55                 // resource id (R.string.short_notification_text).  There is also
56                 // a version that takes a CharSequence if you must construct
57                 // the text yourself.
58                 Toast.makeText(NotifyWithText.this, R.string.short_notification_text,
59                     Toast.LENGTH_SHORT).show();
60             }
61         });
62 
63         // long notification
64         // The only difference here is that the notification stays up longer.
65         // You might want to use this if there is more text that they're going
66         // to read.
67         button = (Button) findViewById(R.id.long_notify);
68         button.setOnClickListener(new Button.OnClickListener() {
69             public void onClick(View v) {
70                 Toast.makeText(NotifyWithText.this, R.string.long_notification_text,
71                     Toast.LENGTH_LONG).show();
72             }
73         });
74 
75 
76 
77 
78 
79     }
80 }
81