Home » » Android Simple EditText Example

Android Simple EditText Example

Written By MR HARI on Kamis, 28 April 2011 | 03.48


SIMPLE EDITTEXT

SOURCE CODE [main.xml] is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />

<EditText android:id="@+id/edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />

    <Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show the Text" />

</LinearLayout>

SOURCE CODE [EditTextExample.java] is

package com.EditTextExample;

import android.app.Activity;
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 EditTextExample extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
                               
final EditText et;
final Button b;
       
et = (EditText) findViewById(R.id.edittext);
b = (Button) findViewById(R.id.button);
       
                                b.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
                                                                String text=et.getText().toString();
                                                               
                                                Toast msg = Toast.makeText(getBaseContext(),
                                                                                text, Toast.LENGTH_LONG);
msg.show();
                                                }
                                });
}
}

The OUTPUT will be


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSQ18dJ8uf5oTFu9hh392yHS2f3aSqLOIUNILUlxSpqikwqqbeOcmrb8-x7UEkqoQ1E_YZxUgWe5vS1IEedOdVP7GSeDlbw2O1m0n8_kRpRwLNro9vTnMTbFAMCaYcH0o4dhZ48jB1Np4/


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgplNIQdEzTRPWMFrQE1_bBvrMivllkB6MMEcoG4uPOgN8KeFLSd6znfEEH3H1xRmmgGzzLet2wtUJ_ZInFLv_0rRpiwppMAft6J7h6Is8PwIFU25aaIPvixwWA6dBOsGt6-yB-lqoJaYM/
Share this article :

0 komentar:

Posting Komentar

 
Support : Your Link | Your Link | Your Link
Copyright © 2013. Android Center - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger