Help, I have this switch statement inside my code, but I want to include an if statement, but its not working.

   if (valueSumIndex > 10000) {
       Toast.makeText(getActivity(), "You are Over Spending", 
        Toast.LENGTH_SHORT).show();
         }
@Override
   public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
     switch (loader.getId()) {
         case SUM_LOADER_ID:
             int valueSumIndex = data.getColumnIndex(Expenses.VALUES_SUM);
             data.moveToFirst();
             float valueSum = data.getFloat(valueSumIndex);
             mTotalValueTextView.setText(Utils.formatToCurrency(valueSum));

             if (valueSum > 10000) {
                 Toast.makeText(getActivity(), "You are Over Spending", 
  Toast.LENGTH_SHORT).show();
             }
             break;

         case LIST_LOADER_ID:
             // Hide the progress bar
             mProgressBar.setVisibility(View.GONE);
             // Update adapter's data
             mAdapter.swapCursor(data);
             break;
     }

What I want is a notification instead of a toast saying you are overspending after spending more that 10000.

2 Answers

0
евгений кунцевич On

I tried something like you used and it worked nice.

public static void main(String[] args) {
    switch (2) {
        case 1: //do something
        case 2:
            int a = 2 + 1;
            if (a > 1) {
                System.out.println("It's works!");
            }
    }
}

It looks like that switch-statement don't exclude using if-statement inside.

0
Sandeep Malik On

you can do this way:-

@Override
   public void onLoadFinished(Loader<Cursor> loader, Cursor data) {

       if(loader.getId() == R.id.yourId){
           //your condition
         }else if(loader.getId() == R.id.yourId){
           //your condition
         }
}