Toast
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class ToastActivity extends Activity implements OnClickListener{
/** Called when the activity is first created. */
EditText et;
Button bt;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
et=(EditText) findViewById(R.id.editText1);
bt=(Button) findViewById(R.id.button1);
bt.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(this,et.getText().toString(), Toast.LENGTH_SHORT).show();
}
}
- A toast is a view congaing a quick little message for the user
- Toast.show()--Show the view for the specified duration.
- Toast.makeText (Context context, CharSequence text, int duration);
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class ToastActivity extends Activity implements OnClickListener{
/** Called when the activity is first created. */
EditText et;
Button bt;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
et=(EditText) findViewById(R.id.editText1);
bt=(Button) findViewById(R.id.button1);
bt.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(this,et.getText().toString(), Toast.LENGTH_SHORT).show();
}
}
----------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText android:id="@+id/editText1"
android:layout_height="wrap_content"
android:layout_x="98dp"
android:layout_y="101dp"
android:layout_width="83dp">
</EditText>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button1"
android:text="OK"
android:layout_x="113dp"
android:layout_y="180dp">
</Button>
</AbsoluteLayout>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText android:id="@+id/editText1"
android:layout_height="wrap_content"
android:layout_x="98dp"
android:layout_y="101dp"
android:layout_width="83dp">
</EditText>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button1"
android:text="OK"
android:layout_x="113dp"
android:layout_y="180dp">
</Button>
</AbsoluteLayout>
No comments :
Post a Comment