Riley B Riley B - 3 months ago 11
Android Question

Button's onClick() not getting called

I am trying to make a call button whereby when a user clicks on a button, it makes a phone call.

Now I have the Radio Button and the code for the button but when clicked it does nothing.

I already have the

CALL_PHONE
and
READ_PHONE_STATE
permissions set in the manifest but still not working when the button is pressed.

Here is my code for the radio button in the activity:

Button radioButton;
call();


radioButton = (Button) findViewById(R.id.radioButton);
}

private void call()
{
Intent in = new Intent(Intent.ACTION_DIAL,Uri.parse("0000000000"));
try{
startActivity(in);
}
catch (android.content.ActivityNotFoundException ex)
{
Toast.makeText(getApplicationContext(),"yourActivity is not founded",Toast.LENGTH_SHORT).show();
}
}

Answer

create RadioGroup and then RadioButton inside RadioGraoup

RadioGroup radioGroup = (RadioGroup) findViewById(R.id.yourRadioGroup);        
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() 
{
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        RadioButton callRadioButton=(RadioButton)findViewById(checkedId);

        //gettext you write with radiobutton
        String  dailString=callRadioButton.getText().toString();

        //check if you select the radio button
        if(dailString.trim().equals("dailnumber"){
            Intent intent = new Intent(Intent.ACTION_DIAL);
            intent.setData(Uri.parse("tel:0123456789")); 
            startActivity(intent); 
        }else{ 
        // do action with other android button
        }
    } 
});
Comments