I have two layouts.
One is activity_main.xml
and the other one is another_activity.xml
On activity_main
I made a login screen. So you have to put your name and press "log in".
user_field = (EditText)findViewById(R.id.name_field);
presentation = (TextView)findViewById(R.id.textView2);
Button signup = (Button)findViewById(R.id.login_butt);
signup.setOnClickListener(new OnClickListener() {
public void onClick(View view){
String danut = user_field.getText().toString();
setContentView(R.layout.another_activity);
presentation.append("danu");
}
});
After you insert your name and press Sign up, it will redirect you to the second layout and prompt your name, "Welcome, your name".
I tried to switch the instructions in OnClick ( by setting the content view after append instruction, and still not succes)
So the result is: you put your name, press the signup/login button, you are redirected to the new page and there is only "Welcome, " and nothing.
Thanks in advance.
UPDATE:
EditText user_field;
TextView presentation;
String final_text = "";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button aprinde =(Button)findViewById(R.id.aprinde);
Button sting = (Button)findViewById(R.id.sting);
Button signup = (Button)findViewById(R.id.login_butt);
user_field = (EditText)findViewById(R.id.name_field);
presentation = (TextView)findViewById(R.id.textView2)
signup.setOnClickListener(new OnClickListener()
{
public void onClick(View view)
{
String danut = user_field.getText().toString();
final_text = "Welcome, " + danut;
setContentView(R.layout.another_activity);
presentation.setText(final_text);
}
}
);
Full Code + picture.
https://i.stack.imgur.com/J3ImY.png
The result on emulator, is the same as the preview ib the picture.