• Android 的一些提示框


    1.在测试时,如何实现一个提示

    可以使用

    1. Toast.makeText(this, "这是一个提示", Toast.LENGTH_SHORT).show();
    2. //从资源文件string.xml 里面取提示信息
    3. Toast.makeText(this, getString(R.string.welcome), Toast.LENGTH_SHORT).show();

    这个提示会几秒钟后消失

    2.可以使用AlertDialog.Builder 才产生一个提示框.

       例如像messagebox那样的

    1.    new AlertDialog.Builder(this)
    2.      .setTitle("Android 提示")
    3.      .setMessage("这是一个提示,请确定")
    4.      .show();

    带一个确定的对话框

    1. new AlertDialog.Builder(this)
    2.           .setMessage("这是第二个提示")
    3.           .setPositiveButton("确定",
    4.                          new DialogInterface.OnClickListener(){
    5.                                  public void onClick(DialogInterface dialoginterface, int i){
    6.                                      //按钮事件
    7.                                   }
    8.                           })
    9.           .show();

    AlertDialog.Builder 还有很多复杂的用法,有确定和取消的对话框

    1. new AlertDialog.Builder(this)
    2.          .setTitle("提示")
    3.          .setMessage("确定退出?")
    4.          .setIcon(R.drawable.quit)
    5.          .setPositiveButton("确定", new DialogInterface.OnClickListener() {
    6.         public void onClick(DialogInterface dialog, int whichButton) {
    7.          setResult(RESULT_OK);//确定按钮事件
    8.          finish();
    9.          }
    10.          })
    11.          .setNegativeButton("取消", new DialogInterface.OnClickListener() {
    12.         public void onClick(DialogInterface dialog, int whichButton) {
    13.          //取消按钮事件
    14.          }
    15.          })
    16.          .show();

    3.menu 的用法.

    1. public static final int ITEM_1_ID = Menu.FIRST;
    2. public static final int ITEM_2_ID = Menu.FIRST + 1;
    3. public static final int ITEM_3_ID = Menu.FIRST + 2;
    4.     
    5. public boolean onCreateOptionsMenu(Menu menu) {
    6.          super.onCreateOptionsMenu(menu);
    7. //不带图标的menu
    8.          menu.add(0, ITEM_1_ID, 0, "item-1");       
    9. //带图标的menu
    10.          menu.add(0, ITEM_2_ID, 1, "item-2").setIcon(R.drawable.editbills2);
    11.          menu.add(0, ITEM_3_ID, 2, "item-3").setIcon(R.drawable.billsum1);
    12.         return true;
    13. }
    14. public boolean onOptionsItemSelected(MenuItem item){
    15.        switch (item.getItemId()) {
    16.        case 1:
    17.             Toast.makeText(this, "menu1",Toast.LENGTH_SHORT).show();            
    18.            return true;
    19.        case 2:
    20.         
    21.            return true;
    22.        case 3:
    23.          
    24.            return true;
    25.         }
    26.        return false;
    27.      }

    4.Activity 的切换

         2个Activity 的切换,没有数据传递

    1. //从A到B
    2. Intent intent = new Intent();
    3.                  intent.setClass(A.this, B.class);
    4.                  startActivity(intent);

    2个Activity 之间传递数据

        相关的几个函数
         startActivityForResult
        public final void setResult(int resultCode, String data)
        回调函数

        protected void onActivityResult(int requestCode, int resultCode, Intent data)

     

        例如A到B,从B得到数据  

    1. //A到B
    2. static final int RG_REQUEST = 0;
    3. Intent intent = new Intent();
    4. intent.setClass(A.this, B.class);
    5. startActivityForResult(intent,RG_REQUEST);
    6.                                   
    7. //在B中处理
    8. Bundle bundle = new Bundle();
      bundle.putString("DataKey", edittext.getText().toString());//给bundle 写入数据
      Intent mIntent = new Intent();
      mIntent.putExtras(bundle);
      setResult(RESULT_OK, mIntent);
      finish();
    9. //最后在A的回调函数里面接收数据
    10. if (requestCode == RG_REQUEST) {
           if (resultCode == RESULT_CANCELED)
                 setTitle("Canceled...");
           else if(resultCode == RESULT_OK) {
                setTitle((String)data.getCharSequenceExtra("DataKey"));
              }
      }

    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/sunnyclare/archive/2010/03/23/5408217.aspx

  • 相关阅读:
    分布式大数据高并发的web开发框架
    用户安全登录问题
    成功扩展live555支持ipv6,同时支持RTSPServer & RTSPClient
    经过两个多月的攻关,终于搞定了live555多线程并稳定压测通过
    经过两个多月的攻关,终于搞定了live555多线程并稳定压测通过
    如何使用EasyNVR+CDN突破萤石云在直播客户端数量上的限制,做到低成本高性价比的直播
    EasyNVR完美搭配腾讯云CDN/阿里云CDN进行RTMP、HLS直播加速的使用说明
    NVR硬件录像机web无插件播放方案功能实现之相关接口注意事项说明
    EasyNVR实现海康、大华NVR硬盘录像机Web无插件播放方案(支持取特定时间段视频流)
    EasyNVR无插件直播服务如何配合EasyBMS使用以及实现流媒体管理功能概述
  • 原文地址:https://www.cnblogs.com/lixiaolun/p/3379892.html
Copyright © 2020-2023  润新知