Powered by Blogger.

Followers

Sunday, 24 February 2013

TextView Button and EditText

Posted by Sanjeet A On 09:00 No comments
Introduction To Basic Widgets:-
Today we will make a simple app which will display some stuff given as input. Basic widgets are TextView , Button , EditText etc.So create a new android project
                    App Name:SimpleWidgets
                    ProjectName:SimpleWidgets
                    package Name:in.blogspot.simplewidget
                    Class Name: WidgetsActivity
                    Layout:activity_widget


Now Open Layout xml From Package Explorer and edtit activity_widget.xml as:



<LinearLayout 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:orientation="vertical"
    tools:context=".WidgetActivity" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Please Fill The Details" />

    <EditText
        android:id="@+id/etName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Name"
        android:inputType="textPersonName" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/etNo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Number"
        android:inputType="phone" >
    </EditText>

    <EditText
        android:id="@+id/etAdd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Address"
        android:inputType="textMultiLine" />

    <Button
        android:id="@+id/bDisplay"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Display" />

    <TextView
        android:id="@+id/tvShow"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="-----" />

</LinearLayout>



Switch  it to  Graphical view you will see like this:-
Now select your class file from Package Explorer src>in.blogspot.simplewidget>WidgetsActivity.java
Edit it-




package in.blogspot.thenewtechnoworld;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class WidgetActivity extends Activity implements OnClickListener {
TextView show;
Button display;
EditText name, address, no;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// seting reference to the layout stuffs
setContentView(R.layout.activity_widget);
show = (TextView) findViewById(R.id.tvShow);
display = (Button) findViewById(R.id.bDisplay);
name = (EditText) findViewById(R.id.etName);
address = (EditText) findViewById(R.id.etAdd);
no = (EditText) findViewById(R.id.etNo);

display.setOnClickListener(this);
}

@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_widget, menu);
return true;
}

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String ur_name = name.getText().toString();
String ur_no = no.getText().toString();
String ur_address = address.getText().toString();

show.setText("name:" + ur_name + "\n" + "No:" + ur_no + "\n"
+ "Address:" + ur_address);

}

}


Save it and run. You will see out put as:-



So you finished this app! Enjoy...If getting problem Please comment!!
You can download the source code here, But you will have to be Loged in to Facebook.
Thanks for reading this blog.




Hello Friends..
This is my new blog on Android Application Development. I am on blogger since 5 years and written several posts on poetry and free 3G .
Presently, I am an Android Developer at SARC Software Solution .
                   However there are are tons of video and online tutorials on android ,but still there is no any good fundamental post or video in any forum or blog so a beginner can learn the app development alone. So I am trying to give complete instruction with source code to start the development.



Setting Tools:-
Before you start you need the following tools:
1.JDK 5+
2.Android Developer tools
You can download JDK 7 from oracle's website and developer tool from android's website for windows.

Note:-Android Developer Tool contains Eclipse IDE and ADT Plugin.If you are having already installed jdk and eclipse then read the next post to integrate ADT Plugin .

Now install your jdk and then extract downloaded zip file (developer tools , adt-bundle-windows-x86.zip) into the C drive. Then open>adt-bundle-windows-x86>eclipse and right click on eclipse.exe and create a shortcut to the desktop and open it. You will see the screen like this-
Go to the upper left corner of the screen and close this welcome page .Then set your work space if ask.
Now you have finished 75% tool setup.Rest will be finished after writing first program hello 'android!'.

Go to file and select new>Android Application Project and fill the fields as shown below-


And click next again next,next and next then hit finish.
screen will show like this-

Now close this screen and go to window show view and select Package Explorer. And then select MyFirstApp>src>in.blogspot.thenewtechnoworld>MainActivity.


Now just click the icon below the, search alternatively you can go window>android virtual device manager.


Now select new ..You will see this window empty because yet you did not have created an adv But in this window two adv are there bcoz i have already created them.


Give a new to this adv , select a device , then target it as you wish select other options and then hit ok.
Now You have done almost all setups to develop your first app.

Now just select the green play like icon from your menu bar to run this app. Select run as a android application if asks. Now wait for a while you will see an hell word tag on the new virtual device .

Nice so you  finished your first app..


Thank You for reding this post..
If you are getting any problem just comment or send a mail..

Site search