2 Replies - 125 Views - Last Post: 15 October 2011 - 05:06 AM

#1 hall882006  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 89
  • Joined: 12-February 10

Variable wont stay as a certain value

Posted 14 October 2011 - 10:21 PM

A have an IF statement where i need to check when something occurs and once it occurs i need to get that value to later test the rest of my values in my code. The trouble i am having is that my value wont stay as the number so it doesnt format the rest of my code correctly. Example: The value say it gets from my if statement is 11. I set that value to a variable then test later on any value that is greater than 11.Then it does something until the rest of the values are read. What is happening now tho is that it will set the variable to 11 but only for the IF statement is true that it goes back to zero which i dont want i need it to stay that certain value that it gets until its done reading values.

@Override
			public void bindView(View view, Context context, Cursor cursor) {

				String s = null;
				String am_pm = null;
				String a = null;
				String b = null;
				int count = 0;
				int newNum = 0;
				int count2 = 0;
				int position = cursor.getPosition();


				String mTime = (cursor.getString(cursor
						.getColumnIndex("records")));

				am_pm = "AM";

				if (mTime.length() == 3) {

					a = mTime.substring(0, 1);
					b = mTime.substring(1, 3);

					s = a + ':' + b;

				} else {

					a = mTime.substring(0, 2);
					b = mTime.substring(2, 4);

					s = a + ':' + b;

				}

				if ((mTime.substring(0, 2).equals("12"))) {

					count = cursor.getPosition() + 1;

					count2 = count2 + 1;

					newNum = count - count2;

				}

				if (position >= newNum && newNum != 0) {

					am_pm = "PM";
				}


				String fullString = s + " " + am_pm;

				((TextView) view.findViewById(R.id.timeList))
						.setText(fullString);
			}
		}

		startManagingCursor(cursor);
		setListAdapter(new MyAdapter(this, cursor));

                }



Is This A Good Question/Topic? 0
  • +

Replies To: Variable wont stay as a certain value

#2 farrell2k  Icon User is online

  • 1.21 Jiggawatts!
  • member icon

Reputation: 566
  • View blog
  • Posts: 1,736
  • Joined: 29-July 11

Re: Variable wont stay as a certain value

Posted 15 October 2011 - 05:03 AM

I suspect this is a local scope issue. The info isn't really clear.
Was This Post Helpful? 1
  • +
  • -

#3 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2696
  • View blog
  • Posts: 10,556
  • Joined: 15-July 08

Re: Variable wont stay as a certain value

Posted 15 October 2011 - 05:06 AM

I agree. With the information you are giving us, it sounds like you are binding to a method-scope variable and trying to use it in another method. You need to either pass the variable as an argument or set it to an instance variable.

If this is not your problem, can you phrase your question differently?
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1