Post Top Ad

Post Top Ad

Monday 10 July 2017

#Call Next Send Back


1.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:id="@+id/activity_main"
    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.kiran.task5.MainActivity">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true">

        <TextView
            android:text="Name :"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView2"
            android:layout_weight="1"
            android:textStyle="normal|bold"
            android:textSize="30sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="normal|bold"
            android:textSize="30sp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:id="@+id/name_tv"
            android:layout_weight="1.47" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="39dp"
        android:layout_alignParentStart="true">

        <TextView
            android:text="Age    :"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView3"
            android:layout_weight="1"
            android:textStyle="normal|bold"
            android:textSize="30sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="normal|bold"
            android:textSize="30sp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:id="@+id/age_tv"
            android:layout_weight="1.40" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="83dp"
        android:layout_alignParentStart="true">

        <TextView
            android:text="Telephone :"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView4"
            android:layout_weight="1"
            android:textStyle="normal|bold"
            android:textSize="30sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="normal|bold"
            android:textSize="30sp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:id="@+id/telephone_tv"
            android:layout_weight="3.69" />
    </LinearLayout>

    <Button
        android:text="Call Next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:id="@+id/next_btn"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true"
        android:onClick="callNext"/>

</RelativeLayout>

2.MainActivity.java:

package com.example.kiran.task5;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private TextView mNameTV;
    private TextView mAgeTV;
    private TextView mTelephoneTV;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mNameTV = (TextView) findViewById(R.id.name_tv);
        mAgeTV = (TextView) findViewById(R.id.age_tv);
        mTelephoneTV = (TextView) findViewById(R.id.telephone_tv);
    }

    public void callNext(View view) {
        Intent intent = new Intent(MainActivity.this,SecondActivity.class);
        startActivityForResult(intent,200);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(requestCode==200){
            if(resultCode==RESULT_OK){
                mNameTV.setText(data.getStringExtra("name"));
                mAgeTV.setText(data.getStringExtra("age"));
                mTelephoneTV.setText(data.getStringExtra("telephone"));
            }
        }
    }
}
3.activity_second.java:

<?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:id="@+id/activity_second"
    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.kiran.task5.SecondActivity">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true">

        <TextView
            android:text="Name :"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView2"
            android:layout_weight="1"
            android:textStyle="normal|bold"
            android:textSize="30sp" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:ems="10"
            android:id="@+id/name_et"
            android:layout_weight="1" />

    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="39dp"
        android:layout_alignParentStart="true">

        <TextView
            android:text="Age    :"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView3"
            android:layout_weight="1"
            android:textStyle="normal|bold"
            android:textSize="30sp" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:ems="10"
            android:id="@+id/age_et"
            android:layout_weight="1" />

    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="83dp"
        android:layout_alignParentStart="true">

        <TextView
            android:text="Telephone :"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView4"
            android:layout_weight="1"
            android:textStyle="normal|bold"
            android:textSize="30sp" />

        <EditText
            android:layout_width="164dp"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:ems="10"
            android:id="@+id/telephone_et"
            android:textSize="18sp" />

    </LinearLayout>

    <Button
        android:text="Send Back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:id="@+id/callback_btn"
        android:onClick="callBackData"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true" />

</RelativeLayout>

4.SecondActivity.java:
package com.example.kiran.task5;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class SecondActivity extends AppCompatActivity {

    private EditText mNameEt;
    private EditText mAgeEt;
    private EditText mTelephoneEt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        mNameEt = (EditText) findViewById(R.id.name_et);
        mAgeEt = (EditText) findViewById(R.id.age_et);
        mTelephoneEt = (EditText) findViewById(R.id.telephone_et);
    }

    public void callBackData(View view) {
        Intent intent = new Intent();
        intent.putExtra("name",mNameEt.getText().toString());
        intent.putExtra("age",mAgeEt.getText().toString());
        intent.putExtra("telephone",mTelephoneEt.getText().toString());
        setResult(RESULT_OK,intent);
        finish();
    }
}

No comments:

Post a Comment