20.11.2016 Views

ANDROID APP

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

106 บทที่ 4 ส่วนการติดต่อกับผู้ใช้งาน (User Interface)<br />

<br />

<br />

<br />

<br />

<br />

<br />

วิวที่เรากำหนดไว้ในไฟล์เลย์เอาต์นั้นสามารถทำงานร่วมกับอินสแตนซ์ View ในไฟล์จาวาได้<br />

ตามที่แสดงไว้ในชุดคำสั่งที่ 4.17 เช็คบ็อกซ์ทั้ง 3 อันจะมีคำสั่ง onClickListener อยู่เพื่อคอยตรวจ<br />

จับความเปลี่ยนแปลง และคอยอัพเดตข้อมูลให้แก่ TextView ผลลัพธ์ของชุดคำสั่งนี้แสดงไว้ในรูปที่<br />

4.12<br />

ชุดคำสั่งที่ 4.17 src/com/cookbook/layout_widgets/CheckBoxExample.java<br />

package com.cookbook.layout_widgets;<br />

import android.app.Activity;<br />

import android.os.Bundle;<br />

import android.view.View;<br />

import android.view.View.OnClickListener;<br />

import android.widget.CheckBox;<br />

import android.widget.TextView;<br />

public class CheckBoxExample extends Activity {<br />

private TextView tv;<br />

@Override<br />

public void onCreate(Bundle savedInstanceState) {<br />

super.onCreate(savedInstanceState);<br />

setContentView(R.layout.ckbox);<br />

tv = (TextView) findViewById(R.id.status);<br />

class Toppings {private boolean LETTUCE, TOMATO, CHEESE;}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!