Android The Code
Android The Code
Android The Code
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Activity"
android:textSize="22dp"
android:id="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_below="@+id/textView"
android:layout_margin="30dp"
android:hint="Enter anything..."
/>
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/clickHandle"
android:text="Click"
android:layout_centerHorizontal="true"
android:layout_below="@id/editText"
android:layout_marginTop="25dp"
/>
</
main Activity.java
package com.example.myapplication;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
}
public void onClick(View v) {
Intent intent=new Intent(this,Main2Activity.class);
intent.putExtra("data",editText.getText().toString().trim());
startActivity(intent);
}
}
Activity main2
</LinearLayout>
Main2Activity.java
package com.example.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.content.Intent;
public class Main2Activity extends AppCompatActivity {
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
textView=findViewById(R.id.textView3);
Intent intent= getIntent();
textView.setText(intent.getStringExtra("data"));
}
}