package ex.ToastTest;

import android.app.Activity;
import android.os.Bundle;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;


public class ToastTest extends Activity {
    Toast mToast = null;
    int count;
    String str;

    public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.toasttest);
  
  findViewById(R.id.shortmsg).setOnClickListener(mClickListener);
  findViewById(R.id.longmsg).setOnClickListener(mClickListener);
  findViewById(R.id.count1).setOnClickListener(mClickListener);
  findViewById(R.id.count2).setOnClickListener(mClickListener);
  findViewById(R.id.customview).setOnClickListener(mClickListener);
 }

 Button.OnClickListener mClickListener = new Button.OnClickListener() {
  public void onClick(View v) {
   switch (v.getId()) {
   case R.id.shortmsg:
    Toast.makeText(ToastTest.this, "잠시 나타나는 메시지",
      Toast.LENGTH_SHORT).show();
    break;
   case R.id.longmsg:
    Toast.makeText(ToastTest.this, "조금 길게 나타나는 메시지",
      Toast.LENGTH_LONG).show();
    break;
   case R.id.count1:
    str = "현재 카운트 = " + count++;
    if (mToast != null) {
     mToast.cancel();
    }
    mToast = Toast.makeText(ToastTest.this, str, Toast.LENGTH_SHORT);
    mToast.show();
    break;
   case R.id.count2:
    str = "현재 카운트 = " + count++;
    if (mToast == null) {
     mToast = Toast.makeText(ToastTest.this, str, Toast.LENGTH_SHORT);
    } else {
     mToast.setText(str);
    }
    mToast.show();
    break;
   case R.id.customview:
          LinearLayout linear = (LinearLayout)View.inflate(ToastTest.this,
            R.layout.toast, null);
          Toast t2 = new Toast(ToastTest.this);
          t2.setView(linear);
          t2.show();
          break;
   }
  }
 };
}

 

 

------------------------------------------------------------------------------------------------------------------------------------

toasttest.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<Button
    android:id="@+id/shortmsg"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="짧은 메시지"
    />
<Button
    android:id="@+id/longmsg"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="긴 메시지"
    />
<Button
    android:id="@+id/count1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="카운트 연속 출력"
    />
<Button
    android:id="@+id/count2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="카운트 연속 출력2"
    />
<Button
    android:id="@+id/customview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="커스텀 뷰 표시"
    />
</LinearLayout>

 

자꾸 .java에서 id에러 나는게 뭔이유인지 모르겟어요.

id cannot be resolved or is not failed 라는데. 책에잇는 소스 그대로 해도 에러나더라구요