zoukankan      html  css  js  c++  java
  • EditText/RadioButton/CheckBox使用

    代码
    package com.test.android;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.*;
    import android.widget.CheckBox;
    import android.widget.CompoundButton;
    import android.widget.EditText;
    import android.widget.RadioGroup;
    import android.widget.Toast;

    public class HelloAndroid extends Activity {
        
    private EditText _editText;
        
    /** Called when the activity is first created. */
        @Override
        
    public void onCreate(Bundle savedInstanceState) {
            
    super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
            _editText 
    = (EditText)findViewById(R.id.EditText01);
            _editText.setHint(
    "请输入一个值");
            _editText.setOnKeyListener(
    new EditText.OnKeyListener(){
                
    public boolean onKey(View arg0, int arg1, KeyEvent arg2){
                    dispToast(
    "输入值:"+_editText.getText().toString());
                    
    return false;
                }
            });
            
            RadioGroup rgp 
    = (RadioGroup)findViewById(R.id.RadioGroup01);
            rgp.setOnCheckedChangeListener(
    new RadioGroup.OnCheckedChangeListener(){
                
    public void onCheckedChanged(RadioGroup group, int checkedId){
                    dispToast(Integer.toString(checkedId));
                }
            });
            
            CheckBox cb1 
    = (CheckBox)findViewById(R.id.CheckBox01);
            cb1.setOnCheckedChangeListener(
    new CheckBox.OnCheckedChangeListener(){
                
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){
                    
    if (isChecked){
                        dispToast(
    "选择了"+buttonView.getText().toString());
                    }
                }
            });
        }
        
    public void dispToast(String str){
            Toast.makeText(
    this, str, Toast.LENGTH_SHORT).show();
        }
    }
  • 相关阅读:
    [LeetCode]Sliding Window Maximum
    判断两根线段是否相交
    求幂,我居然又没做出来
    C++集合运算函数总结 & 需要有序集合的操作
    effective stl读书笔记 & stl里面提供的算法 & emplace & ostream_iterator
    利用位操作的几道题目
    C++的new_handler
    TCP的可靠性 窗口滑动 拥塞控制
    关于高性能网络编程的一些知识
    三种连接 & DOS & SYNFLOOD & 防御
  • 原文地址:https://www.cnblogs.com/wjhx/p/1679943.html
Copyright © 2011-2022 走看看