Email: Password:       Forgot Password 
    .netCodeSG
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.
 
TECHNOLOGIES:
 

Showing Message Box in Android Application

Article:
Viewed:  1298 
Posted On:  22/12/2012 21:56:40 
in this article I am going to show how we can use textbox, button, image in Android Application. 

In this article I am going to explain how we can use TextBox, Button and show a message box on click of Button...

In this application I am using a text box to display some text, a button on which click I am showing current DateTime. When we drag text box, button on form then activity_main.xml

1.png
image 1.

<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/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button1"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="34dp"     
        android:text="Rahul Saxena"
        android:textSize="30dp" />
 
    <Button
        android:id="@+id/aboutMeButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="25dp"
        android:layout_marginTop="62dp"
        android:text="Current Time"
        android:onClick="ClickMe" />  
</RelativeLayout>

In <Button Section > see android:onClick="ClickMe" This is the method (ClickMe) which called on button click.

Go to MainActivity.java

package com.example.myfirstapp;
import java.util.Date;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;
 
public class MainActivity extends Activity
 {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
   
    public void ClickMe(View v)
    {
       Date d =new Date();
       Toast.makeText(this, "Current Date "+ d,
       Toast.LENGTH_LONG).show();       

    
}
}

Now to run the application Right Click on MyFirstApp in leftHand pane like in below image...

2.png

Image 2.
 

Simulator is starting up... 

3.png

Image 3.

Your application will look like this in
  Android Mobile 

4.png

Image 4.

Now click on Button...

5.png

Image 5.

  Comment:
         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us