Switching Control

Switching Control
************************** 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:orientation="vertical"
    tools:context=".MainActivity">
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/text"
        android:hint="Enter Name"/>
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/go"
        android:text="GO"/>

</LinearLayout>
************************* switch.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:gravity="center_vertical"
    tools:context=".welo">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:textStyle="italic"
        android:fontFamily="monospace"
        android:textSize="25dp"

        android:id="@+id/view"/>
</LinearLayout>

****************** Main.java *************************

package com.example.switching;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {
EditText send;
Button go;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        send=(EditText) findViewById(R.id.text);
        go=(Button) findViewById(R.id.go);
        go.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String text=send.getText().toString();
                Intent intent=new Intent(MainActivity.this,welo.class);
                intent.putExtra("data",text);
                startActivity(intent);

            }
        });
    }
}

********************welcome.java **************************
package com.example.switching;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class welo extends AppCompatActivity {
TextView textView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welo);
        textView=(TextView)findViewById(R.id.view) ;
        Bundle bundle=getIntent().getExtras();
        String str=bundle.getString("data");

        textView.setText("WELCOME"+str);
      /*  Toast.makeText(this, ""+str, Toast.LENGTH_LONG).show();*/

    }
}



0 Comments