A Toast is a view containing a quick little message for the user. Like Dialog appearance.
See the Example below:
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CLick Me.."
android:id="@+id/click"
android:layout_gravity="center"
/>
</LinearLayout>
Code:
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 ToastexampleActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b1=(Button)findViewById(R.id.click);
b1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(ToastexampleActivity.this, "Your are Clicking..", Toast.LENGTH_LONG).show();
}
});
}
}
See the Output Screen:
More About Toast Click here..
No comments:
Post a Comment