0

I am using an EditText and a Button, when the Button is clicked, the content of the EditText should be shown in a Toast message.

Here is what I tried so far:

public void  cLickFuntion(View view){
    EditText name=(EditText)findViewById(R.id.TvName);
    Toast.makeText(getApplicationContext(),"Hello"+ name.getText().toString(),Toast.LENGTH_SHORT).show();
}
W4R10CK
  • 5,502
  • 2
  • 19
  • 30
Asad Afridi
  • 11
  • 1
  • 1

4 Answers4

3

You can call like this

EditText name=(EditText)findViewById(R.id.TvName);

public void cLickFuntion(View view){
      String nameString=name.getText().toString();
      Toast.makeText(getApplicationContext(),"Hello"+ nameString,Toast.LENGTH_SHORT).show();
}
2

Add code in your onCreate:

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

    EditText name = (EditText)findViewById(R.id.TvName);
    Button One = (Button) findViewById(R.id.your_id);
    One.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(getApplicationContext(),"Hello"+ name.getText().toString(),Toast.LENGTH_SHORT).show();
        }
    });
 }
W4R10CK
  • 5,502
  • 2
  • 19
  • 30
0

add this line to button xml in your layout

android:onClick="cLickFuntion"
A.Arjun
  • 105
  • 3
0
final EditText editText1 = findViewById(R.id.edittext1);
    final EditText editText2=findViewById(R.id.editText2) ;
    Button button=findViewById(R.id.button) ;
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Toast.makeText(getApplicationContext(),"your user name"+editText1.getText().toString(),Toast.LENGTH_LONG).show();
            Toast.makeText(getApplicationContext(),"your password"+editText2.getText().toString(),Toast.LENGTH_LONG).show();
        }
    });