Practical 7
Practical 7
Practical 7
47
Practical 7
Create a new project and go to, activity_main.xml, and make the following additions to the
code.
activity_main.xml
<EditText
android:id="@+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="152dp"
android:textSize="30dp"
android:ems="10"
android:hint="Enter Data"
android:inputType="textPersonName" />
<Button
android:id="@+id/btn1"
android:layout_width="200dp"
android:layout_height="80dp"
android:textSize="30dp"
android:layout_centerInParent="true"
android:text="Send" />
</RelativeLayout>
1
Name: suyash munde Roll no.47
Main_Activity.java
package com.example.prac_7;
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;
import android.os.Bundle;
t1=(EditText)findViewById(R.id.txt1);
b1=(Button)findViewById(R.id.btn1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String data=t1.getText().toString();
Intent intent=new
Intent(getApplicationContext(),DataRecieve.class);
intent.putExtra("data",data);
startActivity(intent);
}
});
}
}
Activity_data_receive.xml
<TextView android:id="@+id/tv1"
2
Name: suyash munde Roll no.47
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginStart="152dp"
android:layout_marginLeft="152dp"
android:layout_marginTop="161dp"
android:layout_marginEnd="132dp"
android:layout_marginRight="132dp" />
</RelativeLayout>
Data_Receive.java
package com.example.prac_7;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.TextView;
import android.os.Bundle;
import android.content.Intent;
public class DataRecieve extends AppCompatActivity {
TextView t1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_data_recieve);
t1=(TextView)findViewById(R.id.tv1);
Intent intent=getIntent();
String data=intent.getStringExtra("data");
t1.setText(data);
}
}
3
Name: suyash munde Roll no.47
Output