Android学习历程-Toast

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/myTextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />
    
    <Button 
        android:id="@+id/myButton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/myTextView"/>
    
    <Button 
        android:id="@+id/myButton2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/myButton"/>

</RelativeLayout>

  

package com.example.testcontextmenu;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class TestToast extends Activity {

	private Button btn1,btn2;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		btn1 = (Button)findViewById(R.id.myButton);
		btn2 = (Button)findViewById(R.id.myButton2);
		final String str1 = "我多显示一会儿!";
		final String str2 ="我少显示一会儿!";
		btn1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Toast t1 = Toast.makeText(getApplicationContext(), str1, Toast.LENGTH_LONG);
				t1.show();
			}
		});
		
		btn2.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Toast t2 = Toast.makeText(getApplicationContext(), str2, Toast.LENGTH_SHORT);
				t2.show();
			}
		});
	}

	
}

  

posted on 2013-03-25 22:28  may小张  阅读(128)  评论(0)    收藏  举报

导航