Hi I would like to pass sqlite data from DbAdapter to MainActivity but I
can't find any helpful questions can help me. I have search for a couple of
weeks now.Below is my code:
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
For example if (countTypesWithTeam()<=4) {Do something} else {keep the
same}, 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);DbAdapter.countTypesWithTeam();
if(DbAdapter.countTypesWithTeam()>=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! I Have ammended my question to make
it more clear. I do not get any errors as the DbAdapter.java runs in the
background
, Thanks
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/4e34205a-43f8-4dd8-adc7-cf73ddcad613%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.