zoukankan      html  css  js  c++  java
  • Android入门笔记1

    1. 按钮事件

       

      演示编辑框、文本显示、按钮事件

      布局:

       

      布局文件:

      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

      xmlns:tools="http://schemas.android.com/tools"

      android:layout_width="match_parent"

      android:layout_height="match_parent"

      android:paddingLeft="@dimen/activity_horizontal_margin"

      android:paddingRight="@dimen/activity_horizontal_margin"

      android:paddingTop="@dimen/activity_vertical_margin"

      android:paddingBottom="@dimen/activity_vertical_margin"

      tools:context=".MyActivity">

      <LinearLayout

      android:layout_width="fill_parent"

      android:layout_height="wrap_content"

      android:orientation="vertical">

      <TextView

      android:layout_width="match_parent"

      android:layout_height="wrap_content"

      android:text="@string/clicknum"

      android:textSize="32dp"/>

      <EditText

      android:id="@+id/numofclick"

      android:layout_width="match_parent"

      android:layout_height="wrap_content"

      android:textSize="32dp"/>

      <Button

      android:id="@+id/btn"

      android:layout_width="match_parent"

      android:layout_height="wrap_content"

      android:text="click!"

      android:textSize="24dp"

      />

      </LinearLayout>

      </RelativeLayout>

       

      Java文件:

      @Override

      protected void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);

      setContentView(R.layout.activity_my);

       

      final EditText ET1= (EditText)findViewById(R.id.numofclick);

       

      Button btn= (Button)findViewById(R.id.btn);

      btn.setOnClickListener(

      new Button.OnClickListener() {

      public void onClick(View v)

      {

      num=num+1;

      Toast.makeText(getApplicationContext(),"dianji",Toast.LENGTH_LONG).show();

      ET1.setText(String.format("点击次数: %d",num));

      }

      }

      );

      }

       

       

      private static int num=0;

       

      获取控件的方法:

      findViewById()

       

      建立事件侦听:

      Button btn= (Button)findViewById(R.id.btn);

      btn.setOnClickListener(

      new Button.OnClickListener() {

      public void onClick(View v)

      {

      }

      });

  • 相关阅读:
    蒙特卡洛采样、重要性采样
    伯努利分布和高斯分布下的最大似然估计、交叉熵
    对于分类问题的神经网络最后一层的函数:sigmoid、softmax与损失函数
    android 侧滑菜单
    安卓Animation类与xml制作动画
    LeetCode题解 #3 Longest Substring Without Repeating Characters
    GY89的使用
    使用GY89的BMP180模块获取温度和压强(海拔)
    STM32与PC机串口通讯
    STM32使用无源蜂鸣器演奏歌曲
  • 原文地址:https://www.cnblogs.com/bacazy/p/3876828.html
Copyright © 2011-2022 走看看