zoukankan      html  css  js  c++  java
  • 安卓高级控件(1)

    1.Toast信息提示框

    Button bt1=(Button)findViewById(R.id.Tbt01);
    Button bt2=(Button)findViewById(R.id.Tbt02);
    bt1.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Toast.makeText(Toast0.this, "按钮1短提示",
                Toast.LENGTH_SHORT).show();
        }
    });
    bt2.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Toast.makeText(Toast0.this, "按钮2长提示",
                Toast.LENGTH_LONG).show();
        }
    });
    View Code

    2.对话框,警告框(Dialog、AlertDialog)

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog);
        bt = (Button) findViewById(R.id.Dbt);
        bt.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Dialog dialog=new AlertDialog.Builder(Dialog0.this)
                    .setTitle("警告")                        //设置标题
                    .setMessage("股市有风险,投资需谨慎")    //显示信息
                    .setIcon(R.drawable.go)                    //设置显示的图片
                    .create();                                //创建Dialog
                dialog.show();            //显示对话框
            }
    });
    警告框代码
                
    接口名称                                        描述
    
    DialogInterface.OnClickListener    对话框单击事件处理接口
    DialogInterface.OnCancelListener    对话框取消事件处理接口
    DialogInterface.OnDismissListener    对话框隐藏事件处理接口
    DialogInterface.OnKeyListener    对话框键盘事件处理接口
    DialogInterface.OnMultiChioceClickListener    对话框多选事件处理接口
    DialogInterface.OnShowListener    对话框显示事件处理接口
                    

    3.对话框操作事件

    Dialog dialog2=new AlertDialog.Builder(Dialog0.this)
        .setTitle("退出")                        //设置标题
        .setMessage("是否退出程序?")        //显示信息
        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                    Dialog0.this.finish();    //退出程序
            }
        })
        .setNeutralButton("取消", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {}
        })
        .create();                            //创建Dialog
        dialog2.show();            //显示对话框
    退出 示例代码
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate (savedInstanceState);
        setContendView(R.layout.dialog);        //设置布局管理器
        Button bt = (Button) findViewById (R.id.button);
        bt.setOnClickListener (new OnClickListener () {
            public void onClick (View v) {
                Dialog dialog2=new AlertDialog.Builder (Dialog0.this)
                    .setTitle("删除")                        //设置标题
                    .setMessage("是否删除指定内容?")        //显示信息
                    .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                        }})
                    .setNeutralButton("取消", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                        }})
                    .create();                //创建Dialog
                dialog2.show();            //显示对话框
                }
            });
    }
    删除 示例代码


     

    4.进度处理事件

    Button bt = (Button) findViewById(R.id.Dbt);
    bt.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            final ProgressDialog pd=ProgressDialog.show(Dialog01.this,
                 "搜索", "正在努力加载中。。。");
            new Thread(){                //线程对象
                public void run(){        //线程主体方法
                    try {
                        Thread.sleep(3000);        //运行3秒后关闭对话框
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }finally{
                        pd.dismiss();    //关闭对话框
                    }
                 }
             }.start();                //线程启动
            pd.show();
         }
    });
    示例代码

    5.SeekBar拖动条

    TextView tv=(TextView)findViewById(R.id.TV);
    tv.setMovementMethod(ScrollingMovementMethod.getInstance());//滚动文本
    SeekBar sb=(SeekBar)findViewById(R.id.seekbar);
    sb.setOnSeekBarChangeListener(
            new OnSeekBarChangeListener() {    //设置操作监听
        public void onProgressChanged(SeekBar seekBar, int progress,
                     boolean fromUser) {
            tv.setText("当前进度"+progress);
         }
         public void onStartTrackingTouch(SeekBar seekBar) {
             tv.setText("正在拖动,当前值"+seekBar.getProgress());
         }
         public void onStopTrackingTouch(SeekBar seekBar) {
             tv.setText("停止拖动,当前值"+seekBar.getProgress());
         }
    });
    示例代码


     

  • 相关阅读:
    C与设计模式---观察者模式
    如何在嵌入式产品中应用键值存储数据库
    Matlab 常用函数小结
    【Qt点滴】游戏2048
    经典ICP算法的问题
    基于矩阵分解的推荐系统实例
    【Qt点滴】UDP协议实例:简易广播实现
    【Qt点滴】:获取本机网络信息
    51单片机:光立方
    STM32单片机:四旋翼飞行器的飞控实现
  • 原文地址:https://www.cnblogs.com/22joke/p/6927142.html
Copyright © 2011-2022 走看看