Lets Start with a simple Project,
Functions : Enter A Text in Edit Text, On Click of a Button show the Text in Text view
Functions : Enter A Text in Edit Text, On Click of a Button show the Text in Text view
Open Eclipse >> File >> New >> Other >> Android(folder) >> Android Project >>Next>>
Enter Project name >> "MyFirstProject" without Quotes >>Next >> Select any available Target(2.1 recommended) >> Next
Give Package name, Package name should be more that two words seperated by "."
Example : vee.sample.demo
Hit Finish.
Open Your Project >> res >> main.xml >> Hit Enter
Drag & Drop the following
- "Edit Text" form Text Fields
- "Button" from Form Widgets
- "Text View" from Form Widgets
Let us do few modifications do Get This to look better.
In Edit Text add
Change the Text
In TextView Add
In Edit Text add
android:hint="Enter Text Here"
Change the Text
"Button" to "Click me"
In TextView Add
android:textSize="25dp" android:textColor="#000" android:background="#fff" android:hint="Output Is Displayed here"
Save.
Open src >> vee.sample.demo >> MyFirstProjectActivity.java
Modify like this, the explanations are Given in form of Comments
For Easy View see Here--> MyFirstProjectActivity.java
For Easy View see Here--> MyFirstProjectActivity.java
package vee.sample.demo; 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.TextView; public class MyFirstProjectActivity extends Activity { // Declaration Starts here // we have added 3 objects EditText, Button, TextView EditText e; Button b; TextView t; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Connecting Objects in xml to declared Variables e = (EditText) findViewById(R.id.editText1); // Edittext should be // connected to Edittext // only b = (Button) findViewById(R.id.button1); t = (TextView) findViewById(R.id.textView2); // Output Should be // displayed below // Button, it's id is // android:id="@+id/textView2" // On clicking the Button, fetch the values entered in Edittext // Store in temp string // display in TextView // type "b.seton" & Hit Ctrl+Space, then type "new" hit Ctrl+Space // u will get the below easily b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // Function Goes here // Fetch the Values from EditText String temp = e.getText().toString(); // set temp values to TextView t.setText(temp); } }); } }Run the Project as Android Application.