-1

I need help..

I have two classes Class1.java and Class2.java. In Class1 one button(PAY) is there to goto Class2. Class2 is Billing Activity and it has one button to go back to Class1.

Button Color should changed when Billing is completed for current month. I want Class1 button to be disable from current date to 1st of next month and enable every 1st of month..

I have tried but havn't got anything...

This is my code..

Class1.java

Intent i=new Intent(Class1.this,Class2.class);<br>
startActivityForResult(i, 123);


protected void onActivityResult(int requestCode, int resultCode, Intent data){        
    super.onActivityResult(requestCode, resultCode, data);<br>
    if (requestCode == 123) {
        pay.getBackground().setColorFilter(ContextCompat.getColor(this,
                R.color.Green), PorterDuff.Mode.MULTIPLY);
        pay.setEnabled(false);
    }
}

Class2.java

Intent i1=new Intent(Class2.this,Class1.class);<br>
setResult(123,i1);<br>
PreetyK
  • 445
  • 5
  • 13
  • button.setEnabled(billing.isCompleted()) ... something like that – Stultuske Dec 18 '17 at 10:51
  • What is the current result which you are getting? The button is still enabled after `onActivityResult()` is executed? – Saran Sankaran Dec 18 '17 at 11:01
  • you need to save the month that billing is completed then use the calendar to get the current month and see if billing was completed or not. Then disable the button based on that – RobVoisey Dec 18 '17 at 11:02
  • Recommend you look at this article: https://developer.android.com/reference/java/util/Calendar.html – RobVoisey Dec 18 '17 at 11:02
  • You can can keep two variables in shared preference one for days and one for date you start counting days then match preference date with current date and find difference if difference match with your preference days then enable button else don't. – Vivek Barai Dec 18 '17 at 11:08

2 Answers2

0

Class2.java

Intent intent = new Intent();
intent.putExtra("isBillCompleted", true);
setResult(123, intent);

Class1.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode ==123 && resultCode == RESULT_OK){
        boolean isCompleted = data.getBooleanExtra("isBillCompleted", false);
        if (isCompleted){
            pay.setBackgroundColor(getResources().getColor(R.color.colorAccent));
            pay.setEnabled(false);
        }
    }
}

Also don't forget to add @Override ano

  • Thanks for response sir...These work well till i stop the app after restart the app the button is enable with the prev button color.. – Mazher Khan Dec 18 '17 at 11:31
0

If you are new to the android technology look after Shared Preferences.

Get the current time in milliseconds and convert it into the days minus the previous billing time if the difference is more than 30 days enable the button or keep it disabled. Once the billing is done reset the BILLED_ON to the current date.

long timeDifference = TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis()) - sharedPreferences.getLong("TIMING", TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis()));
button.setEnabled(timeDifference > 30);

Hope it helps.

Reyansh Mishra
  • 1,811
  • 1
  • 11
  • 23