Shevan Murat Shevan Murat - 4 months ago 7
Android Question

Linking 2 EditText to global variable and button to make a phone call

I'm trying to make an app that makes a call based off two

editText
calls.

The instances are
editText1
and
editText2
. Once filled out, they click add pin to phone. I am able to get it to go to the phone call but only:

*215*null*null


shows up.

So, my question is what am I doing wrong if I want to store whats typed in
edit Text1
to be stored in
firstNumber
and
editText2
to be stored in
secondNumber
?

Furthermore, how do I get the
#
character to display?

So, the result of what I want is:

*215*firstNumber*secondNumber#


to be displayed on phone call.

public class Main2Activity extends AppCompatActivity {

EditText firstNumber;
EditText secondNumber;
Button btnAdd;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);


btnAdd.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {

firstNumber = (EditText)findViewById(R.id.editText2);
secondNumber = (EditText)findViewById(R.id.editText3);
btnAdd = (Button)findViewById(R.id.button5);


Toast.makeText(Main2Activity.this,
"before the call", Toast.LENGTH_LONG).show();


Intent intent = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:*215*" + firstNumber + "*" + secondNumber + "#" ));
startActivity(intent);
} catch (Exception e) {


}
}
});

}
}

Answer

To get the actual text in EditText, you need to use:

int first = Integer.parseInt(firstNumber.getText().toString());
int second = Integer.parseInt(secondNumber.getText().toString());

EDIT: Try this:

String phoneNumber = firstNumber.getText().toString() + secondNumber.getText().toString();
Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:"+phoneNumber));
startActivity(callIntent);
Comments