I have used a (+/-)button to increment or decrement a counter but I hv set an upper limit 2 so I want to disable the plus button of the ElegantNumberbutton after the counter reaches two,and I want the minus button to stay active.

public class MainActivity extends AppCompatActivity {

ElegantNumberButton numberbutton;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    numberbutton=(ElegantNumberButton)findViewById(R.id.numberButton);
  //  counter=(TextView)findViewById(R.id.counterTxt);



    numberbutton.setOnValueChangeListener(new ElegantNumberButton.OnValueChangeListener() {
        @Override
        public void onValueChange(ElegantNumberButton view, int oldValue, int newValue) {


            String count= numberbutton.getNumber();
            int temp=Integer.parseInt(count);
          if(temp>=2 ) {
              Toast.makeText(MainActivity.this, "NO more casual leave allowed", Toast.LENGTH_SHORT).show();
              numberbutton.setEnabled(false);



          }

        }
    });

}
Answer

If you mean this by ElegantNumberButton, I would say that it is not really a button. It is a RelativeLayout, so its setEnabled() do not change any of the children inside it. For disable the +/- buttons, try the following code:

for (int i = 0; i < numberbutton.getChildCount(); i++) {
   View child = numberbutton.getChildAt(i);
   child.setEnabled(false);
}
  • 1
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions