Hello I want to call an object(username, name, posts) from Mainactivity.java to Main2Activity.java
first layout: The user enter write here name, username and posts and click on the button
second layout: the information the user has given is displayed on the page
I want to save the name, username and posts to used in Second layout
public class MainActivity extends AppCompatActivity {
public String username;
public String name;
public String posts;
EditText usernameinput;
EditText nameinput;
EditText postsinput;
Button confirme;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
usernameinput = (EditText)findViewById(R.id.username);
nameinput = (EditText)findViewById(R.id.name);
postsinput = (EditText)findViewById(R.id.posts);
confirme = (Button)findViewById(R.id.confirme);
username = usernameinput.getText().toString();
confirme.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
name = nameinput.getText().toString();
posts = postsinput.getText().toString();
Intent otheractivity = new Intent(getApplicationContext(),Main2Activity.class);
startActivity(otheractivity);
finish();
showToast(name);
showToast(username);
showToast(posts);
}
});
}
private void showToast(String text){
Toast.makeText(MainActivity.this,text,Toast.LENGTH_SHORT).show();
}
}