Android事件

 

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事件,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。