-1

here I have the code: Here is the main file:

package com.example.work.try1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_launch);

    final View buttonS = findViewById(R.id.button);
    buttonS.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Uri uri = Uri.parse("https://www.navanithiastrolife.com");
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);
        }
    });

    final View button2 = findViewById(R.id.button2);
    button2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String user_name = button2.getText(R.id.editText).toString();
            String password = button2.getText(R.id.editText3).toString();
        }
    });

}

I don't know how to get text from a text box and when a button press is clicked.

Fruchtzwerg
  • 10,999
  • 12
  • 40
  • 49
  • Where You want to put this exit text data..? – Ashutosh Tripathi Oct 03 '17 at 05:31
  • Follow this : [EditText get text](https://stackoverflow.com/questions/4396376/how-to-get-edittext-value-and-display-it-on-screen-through-textview) – N.Moudgil Oct 03 '17 at 05:37
  • Welcome to SO . I suggest you first go through some tutorial before posting Question here. And your question is not even clear enough to answer. – ADM Oct 03 '17 at 05:38
  • You can get this answer from 1000s of links in Google, just literally google how to get text from editText on button click. Please do a google search before making a new question. – Sam Oct 03 '17 at 06:35

2 Answers2

0

Please go through the documentation to understand how to code android apps. You can start from here.

To answer your question...

Let's say there is a Button b and an EditText e. Here is how you would get the text from the edittext when the button is pressed.

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launch);

Button b = (Button)findViewById(R.id.<Button ID>);

b.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            EditText e = (EditText)findViewById(R.id.<EditText ID>);
            String s = e.getText().toString(); //getting the string from the edit text
        }
    });

}
Ankit Arora
  • 110
  • 3
  • 16
0

initialize your view first and then get data from it. like

EditText editText1 = (EditText)findViewById(R.id.editText);
EditText editText2 = (EditText)findViewById(R.id.editText3);
Button button2 = (Button)findViewById(R.id.button2);

and then get text from edittext on button click

button2.setOnClickListener(new View.OnClickListener()
{
    public void onClick(View v)
    {
        String user_name = edittext1.getText().toString();
        String password = edittext2.getText().toString();
    }
});
Mahesh Gawhane
  • 348
  • 3
  • 20