zoukankan      html  css  js  c++  java
  • Android事件

    单击事件

    button.setOnClickListener(new onClickListener(){
    //匿名内部类
    public void onclick(View v){
    String xx= edit.getText().toString();
    textview.setText(xx);
    }	
    });
    

    单选事件

    rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {	
    public void onCheckedChanged(RadioGroup group, int checkedId) {
    // 选中单选按钮事件
    RadioButton rb=(RadioButton)findViewById(checkedId);	
    String temp=rb.getText().toString();
    tv1.setText("性别是:"+temp);
    }
    });
    

    下拉框事件

    sp.setOnItemSelectedListener(new OnItemSelectedListener() {
    //一级联
    public void onItemSelected(AdapterView<?> arg0, View view,
    int position, long id) {
    TextView tView = (TextView) view;
    string = tView.getText().toString();
    tv.setText(string);
    if (string.equals("湖南")) {
    hnAdapter
    .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp2.setAdapter(hnAdapter);
    } else if (string.equals("湖北")) {
    hbAdapter
    .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp2.setAdapter(hbAdapter);
    
    } else if (string.equals("广东")) {
    gdAdapter
    .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp2.setAdapter(gdAdapter);
    
    }
    
    }  

    日期时间事件

    tp.setOnTimeChangedListener(new OnTimeChangedListener(){
    
    public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
    // TODO Auto-generated method stub
    tView.setText(hourOfDay+":"+minute);
    }});
    dp.init(2017 , 06 , 19, new DatePicker.OnDateChangedListener() {
    
    public void onDateChanged(DatePicker view, int year, int monthOfYear,
    int dayOfMonth) {
    // TODO Auto-generated method stub
    tView.setText(" "+year+" "+(monthOfYear+1)+" "+dayOfMonth);
    }
    });  

    长按事件

    //长按图片设置为桌面墙纸 
    iView.setOnLongClickListener(new OnLongClickListener() {
    
    public boolean onLongClick(View v) {
    try {
    EXbg.this.clearWallpaper();
    EXbg.this.setWallpaper(
    EXbg.this.getResources().openRawResource(R.drawable.a));
    tView.setText("设置成功!");
    } catch (Exception e) {
    tView.setText("设置失败!");
    e.printStackTrace();
    }
    return true;
    //两个事件 long--click
    //如果为true 运行两个事件 先运行long 再运行click
    //如果为false 只运行long
    }
    });

    键盘事件

    editText.setOnKeyListener(new OnKeyListener() {
    
    public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (event.getAction()==KeyEvent.ACTION_UP) {
    String str=editText.getText().toString();
    if (str.matches("\w+[@]\w+[.]\w+")) {
    im.setImageResource(R.drawable.a);
    tv.setText("格式正确!");
    }else {
    im.setImageResource(R.drawable.icon);
    tv.setText("格式错误!");
    }
    }
    return false;
    }
    }); 

    触摸事件

    eText.setOnTouchListener(new OnTouchListener() {
    
    public boolean onTouch(View v, MotionEvent event) {
    eText.setText((int) (event.getX()+event.getY()));
    return false;
    }
    });
    

      

  • 相关阅读:
    单例模式(上)单例常见的实现方式
    Netty(六)揭开 BootStrap 的神秘面纱
    Netty(五)Netty 高性能之道
    Netty(四)基于Netty 的简易版RPC
    Netty(三)基于Bio和Netty 的简易版Tomcat
    Netty(二)Netty 与 NIO 之前世今生
    java学习笔记
    Java使用笔记之对象比较
    React学习之受控和非受控组件
    SpringBoot学习之常用注解
  • 原文地址:https://www.cnblogs.com/songjiabo/p/6868675.html
Copyright © 2011-2022 走看看