• 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

     

     

  • 相关阅读:
    swift 初见-4运算符与字符串操作
    IOS中数据持久化1-CoreData
    swift 初见-3
    swift 初见-2
    系统硬件1-短信,打电话
    swift 初见-1
    socket理解流程图
    文件操作方法fscanf
    Prim模板
    树剖求LCA模板
  • 原文地址:https://www.cnblogs.com/xilifeng/p/2656930.html
Copyright © 2020-2023  润新知