zoukankan      html  css  js  c++  java
  • 03常用组件和事件监听

    常用组件

    组件

    Android SDK 提供了名为 android.widget 的包,其中提供了在应用程序界面设计中大部分常用的 UI 可视组件,如文本框、按钮。

    如文单选按钮、按钮、文本框:activity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:gravity="center_horizontal">
    
        <RadioGroup
            android:id="@+id/btn_sex"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <RadioButton
                android:id="@+id/btn_male"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="male"
                />
            <RadioButton
                android:id="@+id/btn_female"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="female"
                />
        </RadioGroup>
        <Button
            android:id="@+id/btn_check"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="显示"
            />
        <TextView
            android:id="@+id/text_show"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text=""
            />
    
    </LinearLayout>
    

    事件

    事件就是,单机组件、滑动屏幕、双击组件等等。

    事件处理有两种方法,一种是直接在组件上设置处理方法,一种是设置监听程序。

    第一种:组件绑定事件

    直接在组件上添加处理方法:

    1. 组件上绑定

    2. 在MainActivity.java文件中定义showMessage方法

    3. 启动虚拟手机,启动程序。单机按钮,文字改变。

    第二种:监听组件事件

    1. 不用组件绑定事件

    2. 在MainActivity.java中,给组件添加监听

    3. 启动程序,在虚拟手机中显示如下:

  • 相关阅读:
    Django之web本质
    Python之队列
    Python之阻塞IO模型与非阻塞IO模型
    *****Python之进程线程*****
    ***Python之UDP***
    Python之FTP实现
    Python之粘包
    Python之目录结构
    Python之套接字
    Linux内核分析:Linux内核启动流程分析
  • 原文地址:https://www.cnblogs.com/mingriyingying/p/14371729.html
Copyright © 2011-2022 走看看