alert message in Android
by mariganesh[ Edit ] 2013-03-01 10:11:39
In Xml code create the button then call the onclick event function in java
In res/activity_main.xml
<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"
android: paddingBottom="@dimen/activity_vertical_margin"
android: paddingLeft="@dimen/activity_horizontal_margin"
android: paddingRight="@dimen/activity_horizontal_margin"
android: paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<EditText
android:id="@+id/mnum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="30dp"
android:layout_marginLeft="96dp"
android:ems="10" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/email"
android:layout_alignParentTop="true"
android:layout_marginLeft="46dp"
android:layout_marginTop="170dp"
android:onClick="searchInUrl"
android:text="@string/button1" />
</RelativeLayout>
In MainActivity.java
package com.firstapp;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
public EditText mnum,memail;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void searchInUrl(View clickedButton) {
mnum = (EditText)findViewById(R.id.mnum); // Get id of text box
String mnumval= mnum.getText().toString();// Get the value of text box
Toast.makeText(getApplicationContext(), memailval+"-#"+mnumval, Toast.LENGTH_SHORT).show(); // alert the value of textbox
}