Adz
Adz

Reputation: 2849

How to take in two different values in android?

basically what I've tried, is to create a XML with two input types decimal. Input A and Input B, and when I click add, these values will get passed onto a class method, and that method will do so and so.

The problem I have is that I have no way of passing the value from an XML file to a java file (I think)

I spent like an hour doing the XML thing only to find out I can't do it.

Can you possibly guide me as to how I might go about doing this?

Upvotes: 0

Views: 51

Answers (2)

Unii
Unii

Reputation: 1617

Your XML contains two editText and one button?

in your java file you should do:

EditText e1 = (EditText)findViewById(R.id.e1); 

EditText e2= (EditText) findViewById(R.id.e2);

and in xml set onClick attribute on button (example onClick="onClick") in code:

public void onClick(View v){

e1.getText.toString(); e2.getText.toString(); //save it to string and you have what you want}

Upvotes: 1

Shashika
Shashika

Reputation: 1161

EditText mEditText1 = (EditText)findViewById(R.id.number1i); 
String val1 = mEditText1.getText().toString();
EditText mEditText2 = (EditText)findViewById(R.id.number2i); 
String val2 = mEditText2.getText().toString();

Upvotes: 2

Related Questions