开发者

Compare values in Android

开发者 https://www.devze.com 2023-02-13 03:31 出处:网络
I am developing a cricket application for Android. How do i compare two values in a while loop? For setting notification, I have stored scores into an array list and also the same score in to another

I am developing a cricket application for Android.

How do i compare two values in a while loop? For setting notification, I have stored scores into an array list and also the same score in to another array list. In a while loop, I need to compare if there is a change in the wickets value.

All values come from a database. My code is below:

public void checkNotfifications(){
        ListIterator<Score> litr = scoreList.listIterator();
        ls = s;
        while (litr.hasNext()) {
            Log.i(MY_DEBUG_TAG, "s.getInnings() = "+Integer.parseInt(s.getInnings()));
            Log.i(MY_DEBUG_TAG, "ls.getInnings() = "+Integer.parseInt(ls.getInnings()));
            Log.i(MY_DEBUG_TAG, "Checking for i notifications..."+Integer.parseInt(s.getInnings())+" 2nd "+Integer.parseInt(ls.getInnings()));
            if(Integer.parseInt(s.getInnings()) == Integer.parseInt(ls.getInnings())){
                Log.i(MY_DEBUG_TAG, "Checking for  w notifications..."开发者_StackOverflow+Integer.parseInt(s.getWickets())+" A "+Integer.parseInt(ls.getWickets()));
                if ( Integer.parseInt(s.getWickets()) > Integer.parseInt(ls.getWickets())) {
                    showNotification("A wicket down");
                }
            }
    /*      if (Integer.parseInt(s.getInnings()) >= Integer.parseInt(ls.getInnings())) {
                ls = s;
            }
    */
            s = litr.next();
            ls = litr.next();


}
}


Are you trying to detect the fall of a wicket during a match?

Is the score list made up of runs for each stroke?

Does getInnings return the current run total?

It looks like you're trying to do: if the score hasn't changed from one stroke to the next check whether a wicket has fallen. If so post a notification.

Are you sure that s and ls contain different things. You appear to be setting them equal at the start.

This is all conjecture on my part as you don't seem to have given us enough information. Are you sure it's your method of comparison inside the while loop which is at fault and not your mental model of the problem?

0

精彩评论

暂无评论...
验证码 换一张
取 消