Android移动终端设计实验二+事件监听实验
实验2:事件监听实验
一、 实验目的 本次实验的目的是掌握控件的基于事件监听内部类、基于事件监听内部匿名类、Activity本身作为事件监听器以及直接绑定到标签等四种常用的事件处理方法。 |
二、 实验环境 Windows7 Eclipse MARS.2 AVD虚拟机 |
三、实验内容及结果 通过实验1设计的登录对话框掌握android系统的事件监听的几种处理方法。具体要求如下: i. 基于事件监听内部类实现事件监听处理; ii. 基于事件监听内部匿名类实现事件监听处理; iii. Activity本身作为事件监听器; iv. 直接绑定到标签; v. 在“登录”按钮事件代码中,判断用户名和密码是否正确。 代码实现和测试结果: 内部类: 代码实现: Activity_main.xml <LinearLayoutxmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="欢迎使用登录系统 -by 庞振男" ></TextView>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/user" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="用户名:"/> <EditText android:id="@+id/username" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="input username"
></EditText> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/pass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密码:"/> <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height= |