Screenshots :
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="com.chantisandroid.exampleapp.MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:hint="Plz enter name" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="send"
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="105dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="@+id/editText2"
android:layout_below="@+id/editText"
android:layout_alignLeft="@+id/editText"
android:layout_alignStart="@+id/editText"
android:layout_alignRight="@+id/editText"
android:layout_alignEnd="@+id/editText"
android:layout_marginTop="20dp"
android:hint="Plz enter number" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText3"
android:layout_below="@+id/editText2"
android:layout_alignRight="@+id/editText2"
android:layout_alignEnd="@+id/editText2"
android:layout_alignLeft="@+id/editText2"
android:layout_alignStart="@+id/editText2"
android:hint="Plz enter website"
android:layout_marginTop="20dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/editText4"
android:layout_below="@+id/editText3"
android:layout_alignRight="@+id/editText3"
android:layout_alignEnd="@+id/editText3"
android:layout_alignLeft="@+id/editText3"
android:layout_alignStart="@+id/editText3"
android:layout_marginTop="20dp"
android:hint="Plz enter email" />
</RelativeLayout>
activity_second.xml :
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="com.chantisandroid.exampleapp.SecondActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/textView"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/textView4"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/textView5"
android:layout_below="@+id/textView4"
android:layout_alignLeft="@+id/textView4"
android:layout_alignStart="@+id/textView4"
android:layout_marginTop="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/textView6"
android:layout_below="@+id/textView5"
android:layout_alignLeft="@+id/textView5"
android:layout_alignStart="@+id/textView5"
android:layout_marginTop="20dp" />
</RelativeLayout>
MainActivity.java :
package com.chantisandroid.exampleapp;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button button;
EditText name,number,website,email;
String string,string2,string3,string4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = (EditText)findViewById(R.id.editText);
number = (EditText)findViewById(R.id.editText2);
website = (EditText)findViewById(R.id.editText3);
email = (EditText)findViewById(R.id.editText4);
button = (Button)findViewById(R.id.button);
button.setOnClickListener(this);
}
@Override
public void onClick(View view) {
string = name.getText().toString().trim();
string2 = number.getText().toString().trim();
string3 = website.getText().toString().trim();
string4 = email.getText().toString().trim();
if(TextUtils.isEmpty(string)){
name.setError("Plz enter your name");
name.requestFocus();
return;
}
if(TextUtils.isEmpty(string2)){
number.setError("Plz enter your number");
number.requestFocus();
return;
}
if(TextUtils.isEmpty(string3)){
website.setError("Plz enter your website");
website.requestFocus();
return;
}
if(TextUtils.isEmpty(string4)){
email.setError("Plz enter your email");
email.requestFocus();
return;
}
long phno = Long.parseLong(string2);
Bundle bundle = new Bundle();
bundle.putString("myname", string);
bundle.putLong("phnum", phno);
bundle.putString("website", string3);
bundle.putString("email", string4);
Intent intent = new Intent(getApplicationContext(), SecondActivity.class);
intent.putExtras(bundle);
startActivity(intent);
}
}
SecondActivity.java :
package com.chantisandroid.exampleapp;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class SecondActivity extends AppCompatActivity {
TextView nametext,numbertext,websitetext,emailtext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
nametext = (TextView)findViewById(R.id.textView);
numbertext = (TextView)findViewById(R.id.textView4);
websitetext = (TextView)findViewById(R.id.textView5);
emailtext = (TextView)findViewById(R.id.textView6);
Intent in = getIntent();
Bundle b = in.getExtras();
String name = b.getString("myname");
String website = b.getString("website");
String email = b.getString("email");
long phnumber = b.getLong("phnum");
String phno = Long.toString(phnumber);
nametext.setText(name);
numbertext.setText(phno);
websitetext.setText(website);
emailtext.setText(email);
}
}
AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.chantisandroid.exampleapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity"></activity>
</application>
</manifest>
No comments:
Post a Comment