Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7887475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:35:26+00:00 2026-06-03T05:35:26+00:00

I’m currently trying to change the int value in an if else statement in

  • 0

I’m currently trying to change the int value in an if else statement in my android application. So far I’ve tried a lot of ways and have searched through the internet but can’t find any solutions regarding this.

Here’s my code.

package sirtat.individualProject.PublicTransportationTimeScheduler;
import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;

import android.view.View;
import android.widget.Button;

import android.widget.Toast;

import android.widget.TimePicker;
import android.widget.DatePicker;

import java.util.Calendar;
import java.util.Locale;
import android.database.Cursor;

public class ScheduleActivity extends Activity {
    SQLiteDatabase db;

    TimePicker timePicker;
    DatePicker datePicker;


    int hour, minute;
    int yr, month, day;


    static String fDate1="DepartureDate";
    static String fDate2="DepartureDate";
    static String fTime="DEPART_TIME";
    static String fTime2="DEPART_TIME";

    public static final String view_Schedule1 = "ViewSchedule1";
    public static final String sBusArrival = "SBusArrivalLocation";
    public static final String sBusDepart = "SBusDepartLocation";
    public static final String sBusArrivalT = "SBusArrivalTime";
    public static final String sBusDepartT = "SBusDepartTime";
    public static final String fDepart = "FlightDeparture";
    public static final String sBusSchedule = "SkyBusSchedule";
    public static final String sBusDate = "SkyBusDate";
    public static final String fDate = "FlightDate";

    private int Min;
    private String VarMin = Min+" " + "minute";


    //private String VarMin = "";

    /** Called when the activity is first created */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.schedule_layout);

        db = openOrCreateDatabase("PublicTransport2" , SQLiteDatabase.CREATE_IF_NECESSARY, null);

        db.setVersion(1);
        db.setLocale(Locale.getDefault());
        db.setLockingEnabled(true); 



        Calendar today = Calendar.getInstance();

        //--GET THE CURRENT DATE--
        yr= today.get(Calendar.YEAR);
        month = today.get(Calendar.MONTH);
        day = today.get(Calendar.DAY_OF_MONTH);

        //--GET THE CURRENT TIME--
        hour = today.get(Calendar.HOUR);
        minute = today.get(Calendar.MINUTE);

        timePicker = (TimePicker) findViewById(R.id.timePicker);

        datePicker = (DatePicker) findViewById(R.id.datePicker);





        //--Button view--
                Button btnOp1 = (Button) findViewById(R.id.btnOption1);
                btnOp1.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View v) {

                        int year1 = datePicker.getYear();
                        int mnth1 = datePicker.getMonth() + 1;
                        int dy1 = datePicker.getDayOfMonth();
                        int hr1 = timePicker.getCurrentHour();
                        int min1 = timePicker.getCurrentMinute();

                        fDate1 = (pad(year1)) + ("-") + (pad(mnth1))
                             + ("-") + (pad(dy1));
                        fTime = (pad(hr1)) + (":") + (pad(min1));

                        ScheduleOp1();  
                            }
                    private Object pad(int b) {
                        // TODO Auto-generated method stub
                        if (b >= 10){
                            return String.valueOf(b);
                        }else{
                           return "0" + String.valueOf(b);
                        }


                    }
                   });  

                Button btnOp2 = (Button) findViewById(R.id.btnScheduleOption2);
                btnOp2.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View v) {

                        int year2 = datePicker.getYear();
                        int mnth2 = datePicker.getMonth() + 1;
                        int dy2 = datePicker.getDayOfMonth();
                        int hr2 = timePicker.getCurrentHour();
                        int min2 = timePicker.getCurrentMinute();

                        fDate2 = (pad2(year2)) + ("-") + (pad2(mnth2))
                             + ("-") + (pad2(dy2));
                            fTime2 = (pad2(hr2)) + (":") + (pad2(min2));

                            ScheduleOp2();



                    }


                    private Object pad2(int c) {
                        // TODO Auto-generated method stub
                        if (c >= 10){
                            return String.valueOf(c);
                        }else{
                           return "0" + String.valueOf(c);
                        }
                    }

                });

            }

    protected void ScheduleOp1() {
        // TODO Auto-generated method stub


        db.execSQL("DROP VIEW IF EXISTS " +view_Schedule1);
        db.execSQL("CREATE VIEW " +view_Schedule1+ " " +
                " AS SELECT " +sBusDepart+ "," +sBusArrival+ "," 
                +sBusDepartT+ "," +sBusArrivalT+ " FROM" + " "
                +fDepart+ " " + "INNER JOIN" + " " +sBusSchedule+ " " +
                "ON " +sBusSchedule+ "." +sBusDate+ "=" +fDepart+ "." 
                +fDate+ " " + "WHERE " +fDate+ "= '" +fDate1+"'"+" "+
                "AND" + " " +sBusDepartT+ " " + "= strftime('%H:%M', '" +fTime+ "', '" +VarMin+"');");

         Cursor cur = fetchAllTodos();
            startManagingCursor (cur);


        if (cur.moveToFirst()) {

            for(int Min = -140; Min >= -150; Min=Min-5)
            {
            Toast.makeText(getBaseContext(), cur.getString(0)+ "  " +cur.getString(1)+ "  "
                     +cur.getString(2)+ "  " +cur.getString(3)+ "\n",
                        Toast.LENGTH_LONG).show();
            }
        }else {
            Toast.makeText(this, "Not found", Toast.LENGTH_LONG).show();
        }
            }     





    protected void ScheduleOp2(){

        Toast.makeText(getBaseContext(), "Date selected:"
                 + fDate2 + "\n" +
                "Time Selected:" + fTime2,
                Toast.LENGTH_LONG).show();
    }


           //fetching records from database
         public  Cursor fetchAllTodos() {   
         return db.query(view_Schedule1, new String [] {sBusDepart, 
                 sBusArrival, sBusDepartT, sBusArrivalT }, null, null, null, null, null);
           }



    }

And here’s the significant part of the code

protected void ScheduleOp1() {
        // TODO Auto-generated method stub


        db.execSQL("DROP VIEW IF EXISTS " +view_Schedule1);
        db.execSQL("CREATE VIEW " +view_Schedule1+ " " +
                " AS SELECT " +sBusDepart+ "," +sBusArrival+ "," 
                +sBusDepartT+ "," +sBusArrivalT+ " FROM" + " "
                +fDepart+ " " + "INNER JOIN" + " " +sBusSchedule+ " " +
                "ON " +sBusSchedule+ "." +sBusDate+ "=" +fDepart+ "." 
                +fDate+ " " + "WHERE " +fDate+ "= '" +fDate1+"'"+" "+
                "AND" + " " +sBusDepartT+ " " + "= strftime('%H:%M', '" +fTime+ "', '" +VarMin+"');");

         Cursor cur = fetchAllTodos();
            startManagingCursor (cur);


        if (cur.moveToFirst()) {

            for(int Min = -140; Min >= -150; Min=Min-5)
            {
            Toast.makeText(getBaseContext(), cur.getString(0)+ "  " +cur.getString(1)+ "  "
                     +cur.getString(2)+ "  " +cur.getString(3)+ "\n",
                        Toast.LENGTH_LONG).show();
            }
        }else {
            Toast.makeText(this, "Not found", Toast.LENGTH_LONG).show();
        }
            }

I tried using a for loop to decrease the values but haven’t been able to get it to work so far. Any suggestions or better solutions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:35:27+00:00Added an answer on June 3, 2026 at 5:35 am

    The local variable Min in

    for(int Min = -140; Min >= -150; Min=Min-5)
    

    is different from the instance member Min in:

    private int Min;
    

    If you want to change the value of your instance member, you need to change your for loop to:

    for(Min = -140; Min >= -150; Min=Min-5)
    

    which by the way you can also write:

    for(Min = -140; Min >= -150; Min-=5)
    

    Also note that changing the value of Min won’t change the value of VarMin automatically. You will need to update VarMin every time you update Min if you want them to be linked.

    Finally, as a side not, the convention in Java is to use small caps for variables: Min => min, VarMin => varMin etc.

    EDIT

    Instead of creating a varMin member, create a private method:

    private String getVarMin() {
        return min+" " + "minute";
    }
    

    and call that method everywhere you are using the varMin variable. That way you make sure that you are always using an up-to-date value of min.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.