• 安卓事件大全


    1 OnClickListener(单击事件)
    组件.setOnClickListener(new OnClickListener() {
      public void onClick(View v) {
        String str = et.getText().toString();
        tv.setText(str);
      }
    });

    2 OnCheckedChangeListener(单选发生变化)
    rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
      public void onCheckedChanged(
        RadioGroup group, int checkedId) {
        RadioButton rb = (RadioButton)
        findViewById(checkedId);
        String str = rb.getText().toString();
        tv.setText(str);
      }
    });


    3 OnItemSelectedListener(下拉列表)
    sp.setOnItemSelectedListener(new OnItemSelectedListener() {
      public void onItemSelected(AdapterView<?> arg0, View view,
      int arg2, long arg3) {
      TextView tv1 = (TextView) view;
      String str = tv1.getText().toString();
      tv.setText(str);
      }

    public void onNothingSelected(AdapterView<?> arg0) {
    }
    }); 

    4 OnTimeChangedListener 时间事件监听

    5 OnFocusChangeListener 焦点事件
    et.setOnFocusChangeListener(new OnFocusChangeListener() {
      public void onFocusChange(View v, boolean hasFocus) {
        if(hasFocus){
        et.setText("");
        }else{
        String str= et.getText().toString();
        tv.setText(str);
      }
    }
    });


    6 OnDateChangeListener
    dp.init(2017, 4, 23, new OnDateChangedListener() {
    public void onDateChanged(DatePicker view, int year, int monthOfYear,
      int dayOfMonth) {
        tv.setText(year+"-"+monthOfYear+"-"+dayOfMonth);
      }
    });

    7 OnLongChangeListener(长按事件)
      <!-- 设置修改桌面背景权限 -->
    <uses-permission android:name="android.permission.SET_WALLPAPER" />
    iv.setOnLongClickListener(new OnLongClickListener() {
      public boolean onLongClick(View v) {
        try {
          Day07.this.clearWallpaper();
          //getResources();//获得资源对象
        InputStream data = getResources().openRawResource(R.drawable.a);
        Day07.this.setWallpaper(data);
        } catch (IOException e) {
          e.printStackTrace();
        }
         return false;
      }
    });

  • 相关阅读:
    autolayout先进的自动布局工具箱
    iOS7自定义back按钮和pop交互手势
    iOS7开发技巧
    UICollectionView专题
    关于AutoLayout(自动布局)那些事儿
    代码统计利器--CLOC
    vue之指令篇 ps简单的对比angular
    从无到有之webpack+vuerouter的简单例子以及各个属性解释
    关于requestanimationframe
    vim常用指令
  • 原文地址:https://www.cnblogs.com/yangchan250/p/6902809.html
Copyright © 2020-2023  润新知