码迷,mamicode.com
首页 > 移动开发 > 详细

Android事件

时间:2014-07-30 00:54:12      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   http   java   color   os   文件   

 

1、Java文件

package com.fish.helloworld;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
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;

public class MainActivity extends Activity {

	private TextView m_TextView;
	private backButton_OnClickListener backButtonListener = new backButton_OnClickListener();
	private clearButton_OnClickListener clearButtonListener = new clearButton_OnClickListener();
	
	class backButton_OnClickListener implements OnClickListener{
		public void onClick(View v){
			m_TextView.setText("back");
		}
	}
	
	class clearButton_OnClickListener implements OnClickListener{
		public void onClick(View v){
			m_TextView.setText("clear");
		}
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.skeleton_activity);
		
		m_TextView = (TextView)findViewById(R.id.text1);
		final Button backButton = (Button)findViewById(R.id.back);
		final Button clearButton = (Button)findViewById(R.id.clear);
		
		backButton.setOnClickListener(backButtonListener);
		clearButton.setOnClickListener(clearButtonListener);
	}

}

 

 

 

2、XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/text1" />
        
    <Button
        android:id="@+id/back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/back" />

    <Button
        android:id="@+id/clear"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/clear" />

</LinearLayout>

 

Android事件,布布扣,bubuko.com

Android事件

标签:android   style   blog   http   java   color   os   文件   

原文地址:http://www.cnblogs.com/sshoub/p/3876725.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!