MMMSffi Button A

ffiA-MMffi'mMTfA

btn.setOnClickListener(this) A ff ^

is A

ft * ^ it m ^ stiff ft onClick() stsmsA'Ai« m m m m a btn.setOnClickListener(listener)^#g®ft*ff{tM,f£ listener iffft onClick()®l msA °

mS(Title)MHAAAA : "this is OK button"

// ---- ex03.java fMASf ---package com.misoo.ex03; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button;

public class ex03 extends Activity { @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.wain); Button btn = (Button)findViewById(R.id.button); Button btn2 = (Button)findViewById(R.id.button2); btn.setOnClickListener(listener); btn2.setOnClickListener(listener2);

OnClickListi^eJlistener = new OnClickListener() {

public void onClick(View v) { setTitle("this is OK button"); }

OnClickListener listener2 = new OnClickListener() { public void onClick(View v) { finish(); }

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android: lay out_width= "fill_parent"

android:layout_height="fill_parent"

<TextView android:id="@+id/tv"

android: lay out_width= "fill_parent"

android:layout_height="wrap_content"

android:text=""

<Button android: id=" @+id/button"

android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="OK"

<Button android: id=" @+id/button2"

android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Exit"

0 0

Post a comment