EvenActivity.java

package com.mw.app.view.activity; import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.Toast; import androidx.annotation.Nullable;import androidx.appcompat.app.AppCompatActivity; import com.mw.app.R; public class EvenActivity extends AppCompatActivity implements View.OnClickListener{    @Override    protected void onCreate(@Nullable Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.event_layout);        Button event_layout_btn1 = findViewById(R.id.event_layout_btn1);        Button event_layout_btn2 = findViewById(R.id.event_layout_btn2);        Button event_layout_btn3 = findViewById(R.id.event_layout_btn3);        Button event_layout_btn4 = findViewById(R.id.event_layout_btn4);         event_layout_btn1.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                Toast.makeText(getApplicationContext(),"匿名类",Toast.LENGTH_LONG).show();            }        });         event_layout_btn3.setOnClickListener(this);        event_layout_btn4.setOnClickListener(new EventServiceImpl());    }     public void eventOnclick(View view){        Toast.makeText(getApplicationContext(),"onclick属性事件",Toast.LENGTH_LONG).show();    }     @Override    public void onClick(View v) {        Toast.makeText(getApplicationContext(),"继承接口",Toast.LENGTH_LONG).show();    }     public class EventServiceImpl implements View.OnClickListener{         @Override        public void onClick(View v) {            Toast.makeText(getApplicationContext(),"实现类",Toast.LENGTH_LONG).show();        }    }} 

event_layout.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical" android:layout_width="match_parent"    android:layout_height="match_parent">    <Button        android:id="@+id/event_layout_btn1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textSize="20dp"        android:text="匿名类"></Button>     <Button        android:id="@+id/event_layout_btn2"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textSize="20dp"        android:onClick="eventOnclick"        android:text="onclick属性"></Button>     <Button        android:id="@+id/event_layout_btn3"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textSize="20dp"        android:text="继承接口"></Button>     <Button        android:id="@+id/event_layout_btn4"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textSize="20dp"        android:text="实现类"></Button></LinearLayout>

更多相关文章

  1. Android(安卓)Style.xml 详解
  2. Android(安卓)Relativelayout布局属性
  3. TextView之二:常用属性
  4. 用android:clipChildren来实现红心变大特效
  5. RelativeLayout常用属性介绍
  6. Android学习日记(UI组件)
  7. Android(安卓)activity属性设置大全
  8. Android(安卓)TextView背景色、圆角、内部填充设置
  9. 关于android:focusable属性

随机推荐

  1. 页面调用ADB操作Android设备
  2. Android Binder 全解析(3) -- AIDL原理剖
  3. Android应用开发提高篇(1)-----获取本地IP
  4. 如何在android的jni线程中实现回调
  5. adb(Android Debug Bridge)(一)
  6. Android新手笔记—Android Studio的安装
  7. TX Android电面问题
  8. Android实现IOS越界回弹的效果
  9. 自己写的一套应用管理系统(包含一套app系
  10. Android中AnimationDrawable使用的简单实