zoukankan      html  css  js  c++  java
  • 4.3给圣诞老人的信息—Toast对象的使用

    4.3给圣诞老人的信息—Toast对象的使用

    目录

    4.3给圣诞老人的信息—Toast对象的使用... 1

    目标... 1

    方法... 1

    代码... 1

    效果... 2

    更多详细用法... 2

     

    目标:使用Toast弹出消息.

    方法:构造一个Toast对象,调用对象的show()方法

    代码:

    package edu.cquptzx.UseToast;

     

    import android.app.Activity;

    import android.os.Bundle;

    import android.text.Editable;

    import android.view.View;

    import android.view.View.OnClickListener;

    import android.widget.Button;

    import android.widget.EditText;

    import android.widget.Toast;

     

    publicclass UseToastActivity extends Activity {

        private Button btn;

        private EditText et;

        /** Called when the activity is first created. */

        publicvoid onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

            setContentView(R.layout.main);

           

            // Find the objects by IDs

            btn = (Button) findViewById(R.id.button);

            et = (EditText) findViewById(R.id.editText);

          

            // add an listener to tha SEND BUTTON.

            btn.setOnClickListener(new OnClickListener()

            {

               publicvoid onClick(View v)

               {

                  //Get the text which the user have input .

                  /* 方案二:使用Editable

                   * 特点,文字获取后可以很方便的进行截取,插入,等操作. */

                  //Editable str;

                  //str = et.getText();

                 

                  /* 方案一:使用String

                   * 特点,文字固定,编辑不方便. */

                  String str = null;

                  str = et.getText().toString();

                 

                  Toast.makeText(getBaseContext(),

                         "Your wish: \n  \" " + str.toString() + " \" \n has been send to  Santa Claus.",

                         Toast.LENGTH_LONG)

                         .show();

               }      

            });

        }

    }

    效果:

    UseToast

    更多详细用法:

    http://www.cnblogs.com/xilifeng/archive/2012/08/12/2634178.html

     

     

    For more questions , contacts me by :

    cquptzx@qq.com or  cquptzx@outlook.com

     

     

  • 相关阅读:
    出差常熟,郁闷中 沧海
    ABAP中程序之间传递参数的办法 沧海
    LSMW中出现No logical path specified. 沧海
    请认真对待生活 沧海
    escape sequence 沧海
    休假一周 沧海
    Print Program and Form Modify 沧海
    下周回南京 沧海
    LO020真麻烦 沧海
    函数讲解函数列表(ZT) 沧海
  • 原文地址:https://www.cnblogs.com/xilifeng/p/2656930.html
Copyright © 2011-2022 走看看