Android开发之布局文件里实现OnClick事件关联处理方法
一般监听OnClickListener事件,我们都是通过Button button = (Button)findViewById(....);
button.setOClickLisener....这种方式来实现。
这段时间看各大开放平台的demo,发现事实上能够在xml中定义好方法名称,在Activity中实现该方法就能够了。
<Button
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="@drawable/title_btn_back"
android:onClick="share_activity_back"
android:text="返回"
android:textColor="#fff"
android:textSize="14sp" />
public void share_activity_back(View v) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
在Activity中直接实现该方法就可以。也无需定义button,实例化它,跟原先一例如便了非常多。
Android开发之布局文件里实现OnClick事件关联处理方法的更多相关文章
- Android -- Layout布局文件里的android:layout_height等属性为什么会不起作用?
有的时候,我们配置好的布局文件,在加载完成添加到我们的Activity中后发现,并没有安装我们设置的属性来布局,比如我们设置了android:layout_marginTop="100dip ...
- Android Layout布局文件里的android:layout_height等属性不起作用
有的时候,我们配置好的布局文件,在加载完成添加到我们的Activity中后发现,并没有安装我们设置的属性 来布局,比为我们设置了android:layout_marginTop="100di ...
- Android开发 --代码布局
Android开发 --代码布局 在线性布局LinearLayout里加入view比较简单,因为属性比较少,布局简单 示例,加入一个TextView LinearLayout layout = (Li ...
- Android开发 ---xml布局元素
1.android:orientation="vertical/horizontal" vertical为垂直布局, horizontal为水平布局 2.android:layou ...
- Android开发---网格布局案例
Android开发---网格布局案例 效果图: 1.MainActivity.java package com.example.android_activity; import android.ap ...
- Android中得到布局文件对象有三种方式
Android中得到布局文件对象有三种方式 第一种,通过Activity对象 View view = Activity对象.getLayoutInflater().inflater(R.layout. ...
- Android开发 UI布局
Android开发 UI布局一.线性布局LinearLayout 什么是线性布局? 其实呢,线性布局就是把所有的孩子摆在同一条线上 <?xml version="1.0" e ...
- 在Android开发中,定时器一般有以下3种实现方法
在Android开发中,定时器一般有以下3种实现方法: 原文地址http://www.360doc.com/content/12/0619/13/87000_219180978.shtml 一.采用H ...
- JS里的onclick事件
可以通过以下代码了解JS里的onclick事件: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml&quo ...
随机推荐
- c++ 中double与string之间的转换,char *
运行代码为 /* * main.cpp * * Created on: Apr 7, 2016 * Author: lizhen */ #include <iostream> //#inc ...
- JavaScript手册
今天偶然找到javasc的手册地址=>js的手册
- POJ2154 Color 【Polya定理 + 欧拉函数】
题目 Beads of N colors are connected together into a circular necklace of N beads (N<=1000000000). ...
- spring+freemarker+redis
1./pom.xml文件内容: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http ...
- [AGC004E] Salvage Robots (DP)
Description 蛤蟆国的领土我们可以抽象为H*W的笼子,在这片蛤土上,有若干个机器人和一个出口,其余都是空地,每次蛤蟆会要求让所有的机器人向某个方向移动一步,当机器人移动到出口时会被蛤蟆活摘出 ...
- 《Java性能权威指南》笔记----JIT编译器
概览 编译型语言(C++,Fortran等):运行程序前,需要用编译器将代码静态编译成CPU可执行的汇编码.汇编码针对特定的CPU. 优点:只需编译一次,且有足够的程序信息来优化汇编码.执行速度快: ...
- redis批量删除脚本
服务器上安装了redis客户端,通过客户端利用脚本对数据批量删除,脚本内容如下: #!/bin/bash name="$1" echo $name ./redis-cli -h r ...
- kernel thread vs user thread
The most important difference is they use different memory, the kernel mode thread can access any ke ...
- Introducing “Razor” – a new view engine for ASP.NET
原文发布时间为:2011-03-24 -- 来源于本人的百度文章 [由搬家工具导入] Razor : cshtml扩展名,用@代替了那些复杂的“耳朵” <% %> ne of the ...
- [LeetCode] Same Tree 深度搜索
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...