ANDROID_MARS学习笔记_S01_002View、监听器初步
一、View、监听器介绍
二、在Activity中获取view和设置属性,设置button的监听器
1.activity_main.xml
<LinearLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.tony.androidfirst.MainActivity" > <TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:background="#FF0000"
android:text="Hello android" /> <Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button"/> </LinearLayout>
2.MainActivity.java
package com.tony.androidfirst; import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView; @SuppressLint("NewApi")
public class MainActivity extends ActionBarActivity { private TextView textView;
private Button button;
int count = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); TextView textView = (TextView) findViewById(R.id.textView);
textView.setText("Hello View");
textView.setBackgroundColor(Color.CYAN); button = (Button) findViewById(R.id.button);
ButtonListener buttonListener = new ButtonListener();
button.setOnClickListener(buttonListener); } class ButtonListener implements OnClickListener { @Override
public void onClick(View v) {
count++;
System.out.println(count);
//textView.setText(count+"");
} }
3.R.java
ANDROID_MARS学习笔记_S01_002View、监听器初步的更多相关文章
- 0032 Java学习笔记-类加载机制-初步
JVM虚拟机 Java虚拟机有自己完善的硬件架构(处理器.堆栈.寄存器等)和指令系统 Java虚拟机是一种能运行Java bytecode的虚拟机 JVM并非专属于Java语言,只要生成的编译文件能匹 ...
- Android_Mars学习笔记_S01_001activity初步
一.activity初步 1.程序启动会先读配置文件AndroidManifest.xml找activity 2.activity会在onCreate方法中读取activity_main.xml文件, ...
- ANDROID_MARS学习笔记_S01_003layout初步
一.layout介绍 二.测试linear_layout1.activity_main.xml <?xml version="1.0" encoding="utf- ...
- elasticsearch学习笔记——安装,初步使用
前言 久仰elasticsearch大名,近年来,fackbook,baidu等大型网站的搜索功能均开始采用elasticsearch,足见其在处理大数据和高并发搜索中的卓越性能.不少其他网站也开始将 ...
- ANDROID_MARS学习笔记_S01_012_SeekBar
1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ...
- ANDROID_MARS学习笔记_S01原始版_005_RadioGroup\CheckBox\Toast
一.代码 1.xml(1)radio.xml <?xml version="1.0" encoding="utf-8"?> <LinearLa ...
- ANDROID_MARS学习笔记_S02_002_Date\TimePicker
一.文档用法 1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" ...
- ANDROID_MARS学习笔记_S02_001_Spinner
1.strings.xml <?xml version="1.0" encoding="utf-8"?> <resources> < ...
- ANDROID_MARS学习笔记_S01原始版_013_广播机制二
一.代码1.xml(1)main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayo ...
随机推荐
- Js 对象二
一.Date对象 1.创建Date对象的方法 1)使用new关键字和Date类来创建(不带参数) Var today = new Date(); //不带参数 它是获取当前的系统时间 2)使用new关 ...
- 【原】GO 语言常见错误
1. Scan error on column index 4: converting string "" to a int: strconv.ParseInt: parsing ...
- linux之gdb使用
gdb是linux下用来调试的一款软件,在这里,我只记录平常经常会用到的知识点,用到什么,就记录什么,在调试环境中去熟悉调试方法和调试工具,这才会加深理解. gdb能够做什么?它可以按照你的定义,随心 ...
- HTML5之广播聊天室
- 服务器端广播文本- 所有客户端都可以收到 --- 客户端 - 定义文本框- 定义发送事件 textarea accesskey =t oninput="sendmsg();"- ...
- Redirect and POST in ASP.NET
http://www.codeproject.com/Articles/37539/Redirect-and-POST-in-ASP-NET
- javassist动态修改class
import java.io.IOException;import java.io.PrintWriter; import javassist.CannotCompileException;impor ...
- laravel5.1关于lists函数的bug
查询语句为: class DateAttrModel extends BaseModel{ -- static function getDays(--){ $days = self::lists('d ...
- UVA 11722
You are going from Dhaka to Chittagong by train and you came to know one of your old friends is goin ...
- mac OS X 10.9.1 配置jdk环境变量
进入命令行 cd ~ touch .bash_profile vi .bash_profile 输入内容jdk变量配置内容: export JAVA_HOME=/Library/Java/JavaVi ...
- 选中excel中的对象
2007在查找和选择中点击“选择对象”,然后再全选全个sheet(ctrl+a)就可以看到了. 2010 “选择对象”在 开始——查找和选择——选择对象