Thursday, March 1, 2012

simply display text box value in android


This program will display the text box value.






The onclick event listener will call when you press button
 

Step1) Main java file goes here
 
package add.number;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import java.lang.*;;


public class AddActivity extends Activity {
      
       Button button1;
    EditText txtbox1;
    TextView tv;
      
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
       
        txtbox1=  (EditText)findViewById(R.id.txtbox1);
        button1 = (Button) findViewById(R.id.button1);
        tv = (TextView) findViewById(R.id.lbl1);
        button1.setOnClickListener(new clicker());
      
       
    }
   
    class clicker implements Button.OnClickListener
    {
    public void onClick(View v)
    {
       String a;
   
       a = txtbox1.getText().toString();
      
       tv.setText(a.toString());
      
      
      
    }
    }
   
   
}



Step2) Content of main.XML file

<?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/txtbox1"
android:layout_width="145px"
android:layout_height="40px"
android:text="EditText"
android:textSize="18sp"
android:layout_x="75px"
android:layout_y="54px"
> 
</EditText>


<Button
android:id="@+id/button1"
android:layout_width="106px"
android:layout_height="36px"
android:text="Button"
android:layout_x="88px"
android:layout_y="224px"
> 
</Button>

<TextView
android:id="@+id/lbl1"
android:layout_width="141px"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_x="76px"
android:layout_y="166px"
> 
</TextView>
   
   
</LinearLayout>

10 comments:

  1. I am new at android programming.
    This helped me understand a few more things!
    Thanks a ton!

    ReplyDelete
  2. Thia code is only for linearLayout?

    ReplyDelete
  3. Hello @Anonymous, that's actually very good choice, you can keep same codebase for both Android and iOS.Are you interested in App Development With Angular then you must be looking for effective development team then you are at the right place for more details on it please go through the website.visit:

    ReplyDelete
  4. Hello @Anonymous, that's actually very good choiceAs Machine Learning & Artificial Intelligence Experts, we can help you inImplementing complex and highly beneficial algorithms that suits your business model. Our data scientists and AI developers will strategically formulate the algorithms depending on your dataset to overcome your core challenges and forthcoming opportunities.For more info on machine learning development servicesvisit:

    ReplyDelete
  5. We are an Android Application Development Company in the USA, providing android application development services for android devices with experienced android app developers.

    ReplyDelete
  6. Very beautifully explained nice blog buddy .Are you among one of those who are looking for Hire Android App Developers then you are at right place we have dedicated development team who are expert in this so what are you waiting for just visit the official website or contact Us.

    ReplyDelete
  7. Very beautifully explained nice blog buddy.If you are looking for Flutter Mobile App Development t then you are at the right place Then you've come to the right place because we have a dedicated development team that is a specialist in this area. So, what are you waiting for? Visit the official website or email us.

    ReplyDelete
  8. Nice information you have shared in blog I am also below sharing few thought on app development please have a look If You are among one of those who are looking for mobile app development company in usa
    then you are at right place we have the robust development team they will develop the app according to your requirements. For more details please visit our website.

    ReplyDelete
  9. The blog was absolutely fantastic! Lot of information is helpful in some or the other way. Keep updating the blog, looking forward for more content...Great job, keep it up. Thank You for this useful information about Application Modernization Services.

    ReplyDelete