Created
May 24, 2011 17:49
-
-
Save agiletalk/989241 to your computer and use it in GitHub Desktop.
[예제] Toast 객체 사용하기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:id="@+id/toastlayout" | |
android:orientation="vertical" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent"> | |
<TextView | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:text="This is custom view" | |
/> | |
</LinearLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.catchabug.ToastTest; | |
import android.app.*; | |
import android.os.*; | |
import android.view.*; | |
import android.widget.*; | |
public class ToastTest extends Activity { | |
Toast mToast = null; | |
int count; | |
String str; | |
/** Called when the activity is first created. */ | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
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; | |
} | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment