activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fb9"
android:orientation="vertical"
android:padding="15dp"
tools:context="com.example.malik.blog.MainActivity">
<EditText
android:id="@+id/editText_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter name" />
<EditText
android:id="@+id/editText_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter email" />
<EditText
android:id="@+id/editText_contact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter contact" />
<AutoCompleteTextView
android:id="@+id/autocomplete_lang"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter language" />
<Spinner
android:id="@+id/spinner_city"
android:layout_width="match_parent"
android:layout_height="40dp"></Spinner>
<Button
android:id="@+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:text="Send to Next Activity" />
</LinearLayout>
MainActivity.java
package com.example.malik.blog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
public class MainActivity extends AppCompatActivity {
EditText name, email, contact;
AutoCompleteTextView language;
Spinner citySpinner;
Button sendButton;
ArrayAdapter<String> langAdapter;
ArrayAdapter<String> cityAdapter;
String[] lang = {"HTML", "CSS", "PHP", "Android"};
String[] city = {"Pune", "Ahmedabad", "Banglore", "Hydrabad"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = (EditText) findViewById(R.id.editText_name);
email = (EditText) findViewById(R.id.editText_email);
contact = (EditText) findViewById(R.id.editText_contact);
language = (AutoCompleteTextView) findViewById(R.id.autocomplete_lang);
citySpinner = (Spinner) findViewById(R.id.spinner_city);
sendButton = (Button) findViewById(R.id.button_send);
langAdapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, lang);
language.setAdapter(langAdapter);
cityAdapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, city);
citySpinner.setAdapter(cityAdapter);
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String NAME = name.getText().toString();
String EMAIL = email.getText().toString();
String CONTACT = contact.getText().toString();
String LANG = language.getText().toString();
String CITY = citySpinner.getSelectedItem().toString();
Intent intent = new Intent(MainActivity.this, ReceiveActivity.class);
intent.putExtra("name_key", NAME);
intent.putExtra("email_key", EMAIL);
intent.putExtra("contact_key", CONTACT);
intent.putExtra("lang_key", LANG);
intent.putExtra("city_key", CITY);
startActivity(intent);
}
});
}
}
activity_receive.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.malik.blog.ReceiveActivity">
<TextView
android:id="@+id/textView_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:text="Name here"
android:textSize="24sp" />
<TextView
android:id="@+id/textView_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:text="Email here"
android:textSize="24sp" />
<TextView
android:id="@+id/textView_contact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:text="Contact here"
android:textSize="24sp" />
<TextView
android:id="@+id/textView_lang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:text="Language here"
android:textSize="24sp" />
<TextView
android:id="@+id/textView_city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:text="City here"
android:textSize="24sp" />
</LinearLayout>
ReceiveActivity.java
package com.example.malik.blog;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class ReceiveActivity extends AppCompatActivity {
private TextView name, email, contact, lang, city;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_receive);
name = (TextView) findViewById(R.id.textView_name);
email = (TextView) findViewById(R.id.textView_email);
contact = (TextView) findViewById(R.id.textView_contact);
lang = (TextView) findViewById(R.id.textView_lang);
city = (TextView) findViewById(R.id.textView_city);
Intent intent = getIntent();
String NAME = intent.getStringExtra("name_key");
String EMAIL = intent.getStringExtra("email_key");
String CONTACT = intent.getStringExtra("contact_key");
String LANG = intent.getStringExtra("lang_key");
String CITY = intent.getStringExtra("city_key");
name.setText(NAME);
email.setText(EMAIL);
contact.setText(CONTACT);
lang.setText(LANG);
city.setText(CITY);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.malik.blog">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
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=".ReceiveActivity"></activity>
</application>
</manifest>
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.malik.blog"
minSdkVersion 18
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}