Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////
- // MainActivity.java //
- //////////////////////
- package com.example.displaydetails;
- import android.support.v7.app.ActionBarActivity;
- import android.widget.*;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- public class MainActivity extends ActionBarActivity {
- EditText name, city, phone;
- Button submit;
- TextView output;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- name = (EditText) findViewById(R.id.name);
- city = (EditText) findViewById(R.id.city);
- phone = (EditText) findViewById(R.id.phone);
- submit = (Button) findViewById(R.id.submit);
- output = (TextView) findViewById(R.id.output);
- submit.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- //op.setText("Hello World!");
- output.setText(name.getText().toString()+"\n"+city.getText().toString()+"\n"+phone.getText().toString());
- }
- });
- }
- @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;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
- ///////////////////////
- // activity_main.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="com.example.displaydetails.MainActivity" >
- <EditText
- android:id="@+id/name"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_centerHorizontal="true"
- android:layout_marginTop="38dp"
- android:ems="10"
- android:hint="@string/name"
- android:inputType="textPersonName" >
- <requestFocus />
- </EditText>
- <EditText
- android:id="@+id/city"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignRight="@+id/name"
- android:layout_below="@+id/name"
- android:layout_marginTop="31dp"
- android:ems="10"
- android:hint="@string/city" />
- <EditText
- android:id="@+id/phone"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@+id/city"
- android:layout_centerHorizontal="true"
- android:layout_marginTop="36dp"
- android:ems="10"
- android:hint="@string/phone"
- android:inputType="number" />
- <Button
- android:id="@+id/submit"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@+id/phone"
- android:layout_centerHorizontal="true"
- android:layout_marginTop="27dp"
- android:text="@string/abc_searchview_description_submit" />
- <TextView
- android:id="@+id/output"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignTop="@+id/submit"
- android:layout_toRightOf="@+id/submit"
- android:text="@string/app_name" />
- </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement