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

     

     

  • 相关阅读:
    技术面试之经验总结
    为何只有两篇文章?
    LOJ6364 烂柯
    mysql批量更新数据(性能优化)
    一个对象的key引发的血案
    总结与元素坐标相关的属性(再也搞不混了)
    利用nodejs搭建服务器,测试AJAX
    初探jquery之强大丰富的选择器
    Web前端开发规范手册
    IE8下标签float导致的bug。
  • 原文地址:https://www.cnblogs.com/xilifeng/p/2656930.html
Copyright © 2011-2022 走看看