0% found this document useful (0 votes)
40 views

Package Import Import Import Import Import Import Import Import Import Public Class Extends

The document contains code for an Android application that displays a button, edit text, and text view. When the button is clicked, the text from the edit text is copied to the text view. The code imports necessary Android classes, defines a MainActivity class that sets the layout on create, gets widget references, and sets an onClick listener for the button to update the text view with the edit text value. The layout XML defines the relative positions and properties of the button, edit text, and text view widgets.

Uploaded by

Ravi Teja
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Package Import Import Import Import Import Import Import Import Import Public Class Extends

The document contains code for an Android application that displays a button, edit text, and text view. When the button is clicked, the text from the edit text is copied to the text view. The code imports necessary Android classes, defines a MainActivity class that sets the layout on create, gets widget references, and sets an onClick listener for the button to update the text view with the edit text value. The layout XML defines the relative positions and properties of the button, edit text, and text view widgets.

Uploaded by

Ravi Teja
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

package com.helloworld; import import import import import import import import import android.os.Bundle; android.app.Activity; android.view.Menu; android.view.

View; android.view.View.OnClickListener; android.widget.Button; android.widget.EditText; android.widget.TextView; android.widget.Toast;

public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btnClickMe = (Button)findViewById(R.id.btnClickMe); final TextView lblClickMe=(TextView)findViewById(R.id.lblClickMe); final EditText txtClickMe = (EditText)findViewById(R.id.txtClickMe); btnClickMe.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub String value = txtClickMe.getText().toString(); lblClickMe.setText(value); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }

XML
<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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:id="@+id/btnClickMe" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="96dp" android:layout_marginTop="91dp" android:text="Click Me" /> <EditText android:id="@+id/txtClickMe" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/btnClickMe" android:layout_centerHorizontal="true" android:layout_marginTop="90dp" android:ems="10" > <requestFocus /> </EditText> <TextView android:id="@+id/lblClickMe" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@+id/btnClickMe" android:layout_below="@+id/txtClickMe" android:layout_marginTop="41dp" android:text="ClickButton" android:textAppearance="?android:attr/textAppearanceLarge" /> </RelativeLayout>

You might also like