Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.example.latihan8">
- <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=".SecondActivity"
- android:label="Second Activity"
- android:parentActivityName=".MainActivity"> // manggil panah back ci atas ujung kiri
- </activity>
- <activity android:name=".MainActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- </manifest>
- =================main
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout
- 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"
- tools:context=".MainActivity">
- <Button
- android:id="@+id/KirimPesan"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="KIRIM PESAN"
- android:layout_alignParentBottom="true"
- android:layout_alignParentEnd="true"
- android:layout_marginEnd="10dp"
- android:layout_marginBottom="10dp"
- android:onClick="kirim"
- />
- <EditText
- android:id="@+id/isipesan"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:layout_toStartOf="@+id/KirimPesan"
- android:layout_marginStart="10dp"
- android:layout_marginBottom="10dp"
- android:hint="Tulis Pesan"
- />
- </RelativeLayout>
- ====second
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout
- 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"
- tools:context=".SecondActivity">
- <TextView
- android:id="@+id/judul"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="10dp"
- android:layout_marginTop="10dp"
- android:text="Pesan Diterima"
- style="bold"
- android:textSize="18sp"
- android:textAppearance="@android:style/TextAppearance.Medium"/>
- <TextView
- android:id="@+id/text_received"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_below="@+id/judul"
- android:layout_marginStart="10dp"
- android:layout_marginTop="10dp"
- android:layout_marginEnd="10dp"
- android:textAppearance="@android:style/TextAppearance.Medium"
- android:textSize="16dp"
- android:background="@android:color/holo_green_light"
- />
- </RelativeLayout>
- ===secon java
- public class SecondActivity extends AppCompatActivity {
- TextView tvPesan2;
- String Pesan2;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_second);
- Intent intent = getIntent();
- tvPesan2 = findViewById(R.id.text_received);
- Pesan2 = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
- tvPesan2.setText(Pesan2);
- }
- ===main java
- package com.example.latihan8;
- import android.content.Intent;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- public class MainActivity extends AppCompatActivity {
- EditText edPesan;
- public static final String EXTRA_MESSAGE = ".latihan8.extra.Message";
- public static final int TEXT_REQUEST = 1;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- edPesan = findViewById(R.id.isipesan);
- }
- public void kirim(View view) {
- Intent intent = new Intent(this, SecondActivity.class);
- String pesan = edPesan.getText().toString();
- intent.putExtra(EXTRA_MESSAGE, pesan);
- //startActivity(intent);
- startActivityForResult(intent, TEXT_REQUEST);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement