0

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.

Xan
  • 45
  • 8

2 Answers2

2

you can use intent, in the first activity you will have the login activity, and in the other one there will be the "Welcome..." pass the data with:

First Activity:

Intent intent = new Intent();
intent.setClass(this, Other_Activity.class);
intent.putExtra("name",danut);
startActivity(intent);

Second Activity:

Intent intent = getIntent();
String name = intent.getStringExtra("name");
Didi78
  • 247
  • 1
  • 15
0

Try this,

String final_text = "";

    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 ;

                    }
                    }
       );

UPDATE: So far what happened is we tried to get the text from the edit text after changing the layout which takes an empty value and only sets the "Welcome," text.

Prokash Sarkar
  • 11,723
  • 1
  • 37
  • 50
  • Its still the same. It's strange because if I put the textview in the same layout as the login page, it works, but If I try to prompt on another layout, doesn't work. – Xan Jul 21 '15 at 11:32