0

i've created a function and set it to onClick, so every time i hit the button this function is called. It is called, but the value of 4 other functions i can't get them in setMessage() function(when we create a dialog box). So the logic is like, after hitting the button first we check which radioId1 is equal to which id, and call the appropriate fucntion(video,cons,news,pict).These 4 funct. return some string. Then i want to add these strings to some text in my dialog box, like ....SetMessage(checkMyId() + "Some text").SetPositiveButton(...)...

but the problem is my function checkMyId is set to onClick, so it recieves an argument View v, and when i call it "mannualy" in SetMessage() it shows error, because i don't know what to put inside that parenthesis. So the question is, what type of data(or whatever) is that View ? i saw some documentation and didn't understood much or at least how to implement that in my problem.

public void checkMyId(View v) {
            int radioId1 = radioGroup.getCheckedRadioButtonId();
            if (radioId1 == R.id.radio_one) {
                video();
            } else if (radioId1 == R.id.radio_two) {
                pict();
            } else if (radioId1 == R.id.radio_three) {
                cons();
            } else news();
    }  

EDITED

Picture of the error

casper
  • 35
  • 9

1 Answers1

0

sir you have 2 way

first try this ( HINT : Don't forget to implement ONCLICK in activity )

public void checkMyId(View v) {

switch (v.getId()) {

    case R.id.radio_one:
        video();
        break;

    case R.id.radio_two:
        pict();
        break;

    case R.id.radio_three:
        cons();
        break;

    default:
        news();
        break;
}

}

sec you can use it in OnCreate ( HINT : this on radio group ) HERE

(findViewById(R.id.radio_one)).setOnCheckedChangeListener(new 
OnCheckedChangeListener() 
{
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        // checkedId is the RadioButton selected
    }
});

____ READ This also for single RB

Hassan Badawi
  • 302
  • 1
  • 10
  • Hey, can u see my question,i tried ur first method, updated that and added the picture of mistake. Same mistake actually @Hassan Badawi – casper Oct 04 '18 at 08:50
  • I'm sorry your quest not clear can you but your class to make us help you , what is that dialog -- can u set your class – Hassan Badawi Oct 05 '18 at 13:40