A
A
Andrey Goroshko2018-08-24 14:56:55
Android
Andrey Goroshko, 2018-08-24 14:56:55

How to make a button inactive until a condition is met android?

I have a button in my application and there is a radiogtoup of three radiobuttons. I want to make it so that until each of the radiobuttons is selected once, until the button is inactive, and then when the condition is met, then make the button active. Here is the code I am using to select the radiobutton:

RadioGroup radGrp = findViewById(R.id.radios);
        radGrp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() 
        {
            @Override
            public void onCheckedChanged(RadioGroup arg0, int id) {
                byte k;
                String color = null;
                switch (id) {

                    case R.id.red:
                        color = "КРАСНЫЙ.";
                        k = 'R';
                        myThreadConnected.write2((byte) 'R');
                        break;
                    case R.id.green:
                        color = "ЗЕЛЕНЫЙ.";
                        k = 'G';
                        myThreadConnected.write2((byte) 'G');
                        break;
                    case R.id.blue:
                        color = "СИНИЙ.";
                        k = 'B';
                        myThreadConnected.write2((byte) 'B');
                        break;
                    default:
                        break;

                        
                }
                selection.setText(getString(R.string.color, color));
            }
        });

and here is the code i use for my button which i want to make active and inactive.
findViewById(R.id.result).setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View view, MotionEvent motionEvent) {
                        if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                            myThreadConnected.write2((byte) 'O');
                            Intent intent = new Intent(MainActivity.this, Results.class);
                            intent.putExtra("currency", formattedDouble);
                            startActivity(intent);
                        }
                        return true;
                    }
                });

I will be very grateful for the help and useful advice.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question