vendredi 8 janvier 2016

sqlite data pass from one activity to new activity

Hi I would like to pass sqlite data from DbAdapter to my Main Activity and can no find any helpful questions that will help me. I have search for a couple of weeks now.

ok my DbAdapter.java has this code in it.

public int countTypesWithTeam(String type, String team, String match_id) {
        Cursor cursor   = null;
        int result      = 0;

        //Get column values.
        try {
            cursor = db.rawQuery("SELECT COUNT(" + KEY_TYPE + ") FROM " + DB_TABLE +
                    " WHERE " + KEY_TYPE + "=Try AND " + KEY_TEAM + "=? AND " + KEY_MATCHID + "=?", new String[]{type, team, match_id});
        } catch (Exception e) {
            Log.e("Database error counting type of events involving a team", e.toString());
            e.printStackTrace();
        }

        //Query result is not empty.
        if (cursor != null && cursor.moveToFirst()) {
            result = cursor.getInt(0);
        }

        return result;
    }

now in the sqlite manager this works and I get a value

now if the MainActivity.java I want to get the value from DbAdapter.java

example if the value is <=4 it should do this if not something else my code below is in the MainActivity.java

case WIN: {// Team won the match.
                    int totalWins = teamAdapter.getColumnValueForTeamInt(teamAdapter.KEY_WINS, team);
                    int bonusPoints = teamAdapter.getColumnValueForTeamInt(teamAdapter.KEY_BONUSPOINTS, team);
                    int totalPoints = teamAdapter.getColumnValueForTeamInt(teamAdapter.KEY_TOTALPOINTS, team);

                    if(fourTries>=4)
                    {
                        teamAdapter.updateSingleColumn(team, teamAdapter.KEY_WINS, totalWins + 1);
                    teamAdapter.updateSingleColumn(team, teamAdapter.KEY_BONUSPOINTS, bonusPoints + 1);
                    teamAdapter.updateSingleColumn(team, teamAdapter.KEY_TOTALPOINTS, totalPoints + 5);
                    } else {
                        teamAdapter.updateSingleColumn(team, teamAdapter.KEY_WINS, totalWins + 1);
                    }
                    teamAdapter.updateSingleColumn(team, teamAdapter.KEY_TOTALPOINTS, totalPoints + 4);
                    //}
                    break;
                }

Hope someone can help me with my code as I have run into a brick wall!

Thanks

Aucun commentaire:

Enregistrer un commentaire