Gym application
up vote
-2
down vote
favorite
I currently want to create my first project app, that will help user to start an adventure in a gym. The code that I provided is for set by given earlier value the spinners with body parts. I've got some methods that I think can be shorter, but I don't know how I can make it. First, I'll explain how it all should work. Let's take a closer look at every method that I have to make everything work.
The first one called getMondayBodyParts
. It has to search in a database for three Strings with a value choose by us body parts from previous layout (to make it more clear - in a previous layout we just have a three Spinners where we can select which body parts we want to train in Monday).
public void getMondayBodyParts(){
Cursor cursor = db.getMondaySplitPlan();
while (cursor.moveToNext()){
mondayFirstBodyPartFirstExerciseString = cursor.getString(1);
mondaySecondBodyPartFirstExerciseString = cursor.getString(2);
mondayThirdBodyPartFirstExerciseString = cursor.getString(3);
}
}
The second method is populateSpinners
, which just populates spinners which will display exercises for specified by us body parts.
public List<String> populateSpinners(String string) {
List<String> data = new ArrayList<>();
switch (string) {
case "shoulders": {
data = db.getShouldersData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "chest": {
data = db.getChestData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "back": {
data = db.getBackData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "biceps": {
data = db.getBicepsData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "triceps": {
data = db.getTricepsData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "forearm": {
data = db.getForearmData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "stomach": {
data = db.getAbsData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "legs": {
data = db.getLegsData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "calf": {
data = db.getCalfData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
}
return data;
}
The third method that I want to change is called setMondayFirstBodyPartExercises
. I don't know how exactly it should look like, but I want to just paste three Strings which will populate spinners with specified data. For example, let's assume that we want to train like legs, biceps, triceps (then this method will sent value from those Strings to populateSpinners
and it will show exercises. For now, I've created three methods which practically look the same with one difference between them.
public void setMondayFirstBodyPartExercises(String bodyPartString, Spinner first, Spinner second, Spinner third) {
List<String> data = populateSpinners(bodyPartString);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
first.setAdapter(adapter);
second.setAdapter(adapter);
third.setAdapter(adapter);
}
public void setMondaySecondBodyPartExercises(String bodyPartString, Spinner first, Spinner second, Spinner third) {
List<String> data = populateSpinners(bodyPartString);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
first.setAdapter(adapter);
second.setAdapter(adapter);
third.setAdapter(adapter);
}
public void setMondayThirdBodyPartExercises(String bodyPartString, Spinner first, Spinner second, Spinner third) {
List<String> data = populateSpinners(bodyPartString);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
first.setAdapter(adapter);
second.setAdapter(adapter);
third.setAdapter(adapter);
}
I want to change this line:
List<String> data = populateSpinners(bodyPartString);
I think it will be better when I call this method three times, and everything will be populated just by one method, instead of three different ones.
java sql android database
New contributor
add a comment |
up vote
-2
down vote
favorite
I currently want to create my first project app, that will help user to start an adventure in a gym. The code that I provided is for set by given earlier value the spinners with body parts. I've got some methods that I think can be shorter, but I don't know how I can make it. First, I'll explain how it all should work. Let's take a closer look at every method that I have to make everything work.
The first one called getMondayBodyParts
. It has to search in a database for three Strings with a value choose by us body parts from previous layout (to make it more clear - in a previous layout we just have a three Spinners where we can select which body parts we want to train in Monday).
public void getMondayBodyParts(){
Cursor cursor = db.getMondaySplitPlan();
while (cursor.moveToNext()){
mondayFirstBodyPartFirstExerciseString = cursor.getString(1);
mondaySecondBodyPartFirstExerciseString = cursor.getString(2);
mondayThirdBodyPartFirstExerciseString = cursor.getString(3);
}
}
The second method is populateSpinners
, which just populates spinners which will display exercises for specified by us body parts.
public List<String> populateSpinners(String string) {
List<String> data = new ArrayList<>();
switch (string) {
case "shoulders": {
data = db.getShouldersData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "chest": {
data = db.getChestData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "back": {
data = db.getBackData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "biceps": {
data = db.getBicepsData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "triceps": {
data = db.getTricepsData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "forearm": {
data = db.getForearmData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "stomach": {
data = db.getAbsData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "legs": {
data = db.getLegsData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "calf": {
data = db.getCalfData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
}
return data;
}
The third method that I want to change is called setMondayFirstBodyPartExercises
. I don't know how exactly it should look like, but I want to just paste three Strings which will populate spinners with specified data. For example, let's assume that we want to train like legs, biceps, triceps (then this method will sent value from those Strings to populateSpinners
and it will show exercises. For now, I've created three methods which practically look the same with one difference between them.
public void setMondayFirstBodyPartExercises(String bodyPartString, Spinner first, Spinner second, Spinner third) {
List<String> data = populateSpinners(bodyPartString);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
first.setAdapter(adapter);
second.setAdapter(adapter);
third.setAdapter(adapter);
}
public void setMondaySecondBodyPartExercises(String bodyPartString, Spinner first, Spinner second, Spinner third) {
List<String> data = populateSpinners(bodyPartString);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
first.setAdapter(adapter);
second.setAdapter(adapter);
third.setAdapter(adapter);
}
public void setMondayThirdBodyPartExercises(String bodyPartString, Spinner first, Spinner second, Spinner third) {
List<String> data = populateSpinners(bodyPartString);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
first.setAdapter(adapter);
second.setAdapter(adapter);
third.setAdapter(adapter);
}
I want to change this line:
List<String> data = populateSpinners(bodyPartString);
I think it will be better when I call this method three times, and everything will be populated just by one method, instead of three different ones.
java sql android database
New contributor
1
What's this app for? Tell us, and make that the title of the question — see How to Ask. Is this an online programming exercise or something? If so, please provide a link in addition to the description.
– 200_success
9 hours ago
I've edited post. :)
– Tymbar
6 hours ago
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
I currently want to create my first project app, that will help user to start an adventure in a gym. The code that I provided is for set by given earlier value the spinners with body parts. I've got some methods that I think can be shorter, but I don't know how I can make it. First, I'll explain how it all should work. Let's take a closer look at every method that I have to make everything work.
The first one called getMondayBodyParts
. It has to search in a database for three Strings with a value choose by us body parts from previous layout (to make it more clear - in a previous layout we just have a three Spinners where we can select which body parts we want to train in Monday).
public void getMondayBodyParts(){
Cursor cursor = db.getMondaySplitPlan();
while (cursor.moveToNext()){
mondayFirstBodyPartFirstExerciseString = cursor.getString(1);
mondaySecondBodyPartFirstExerciseString = cursor.getString(2);
mondayThirdBodyPartFirstExerciseString = cursor.getString(3);
}
}
The second method is populateSpinners
, which just populates spinners which will display exercises for specified by us body parts.
public List<String> populateSpinners(String string) {
List<String> data = new ArrayList<>();
switch (string) {
case "shoulders": {
data = db.getShouldersData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "chest": {
data = db.getChestData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "back": {
data = db.getBackData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "biceps": {
data = db.getBicepsData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "triceps": {
data = db.getTricepsData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "forearm": {
data = db.getForearmData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "stomach": {
data = db.getAbsData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "legs": {
data = db.getLegsData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "calf": {
data = db.getCalfData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
}
return data;
}
The third method that I want to change is called setMondayFirstBodyPartExercises
. I don't know how exactly it should look like, but I want to just paste three Strings which will populate spinners with specified data. For example, let's assume that we want to train like legs, biceps, triceps (then this method will sent value from those Strings to populateSpinners
and it will show exercises. For now, I've created three methods which practically look the same with one difference between them.
public void setMondayFirstBodyPartExercises(String bodyPartString, Spinner first, Spinner second, Spinner third) {
List<String> data = populateSpinners(bodyPartString);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
first.setAdapter(adapter);
second.setAdapter(adapter);
third.setAdapter(adapter);
}
public void setMondaySecondBodyPartExercises(String bodyPartString, Spinner first, Spinner second, Spinner third) {
List<String> data = populateSpinners(bodyPartString);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
first.setAdapter(adapter);
second.setAdapter(adapter);
third.setAdapter(adapter);
}
public void setMondayThirdBodyPartExercises(String bodyPartString, Spinner first, Spinner second, Spinner third) {
List<String> data = populateSpinners(bodyPartString);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
first.setAdapter(adapter);
second.setAdapter(adapter);
third.setAdapter(adapter);
}
I want to change this line:
List<String> data = populateSpinners(bodyPartString);
I think it will be better when I call this method three times, and everything will be populated just by one method, instead of three different ones.
java sql android database
New contributor
I currently want to create my first project app, that will help user to start an adventure in a gym. The code that I provided is for set by given earlier value the spinners with body parts. I've got some methods that I think can be shorter, but I don't know how I can make it. First, I'll explain how it all should work. Let's take a closer look at every method that I have to make everything work.
The first one called getMondayBodyParts
. It has to search in a database for three Strings with a value choose by us body parts from previous layout (to make it more clear - in a previous layout we just have a three Spinners where we can select which body parts we want to train in Monday).
public void getMondayBodyParts(){
Cursor cursor = db.getMondaySplitPlan();
while (cursor.moveToNext()){
mondayFirstBodyPartFirstExerciseString = cursor.getString(1);
mondaySecondBodyPartFirstExerciseString = cursor.getString(2);
mondayThirdBodyPartFirstExerciseString = cursor.getString(3);
}
}
The second method is populateSpinners
, which just populates spinners which will display exercises for specified by us body parts.
public List<String> populateSpinners(String string) {
List<String> data = new ArrayList<>();
switch (string) {
case "shoulders": {
data = db.getShouldersData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "chest": {
data = db.getChestData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "back": {
data = db.getBackData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "biceps": {
data = db.getBicepsData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "triceps": {
data = db.getTricepsData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "forearm": {
data = db.getForearmData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "stomach": {
data = db.getAbsData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "legs": {
data = db.getLegsData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
case "calf": {
data = db.getCalfData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
}
}
return data;
}
The third method that I want to change is called setMondayFirstBodyPartExercises
. I don't know how exactly it should look like, but I want to just paste three Strings which will populate spinners with specified data. For example, let's assume that we want to train like legs, biceps, triceps (then this method will sent value from those Strings to populateSpinners
and it will show exercises. For now, I've created three methods which practically look the same with one difference between them.
public void setMondayFirstBodyPartExercises(String bodyPartString, Spinner first, Spinner second, Spinner third) {
List<String> data = populateSpinners(bodyPartString);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
first.setAdapter(adapter);
second.setAdapter(adapter);
third.setAdapter(adapter);
}
public void setMondaySecondBodyPartExercises(String bodyPartString, Spinner first, Spinner second, Spinner third) {
List<String> data = populateSpinners(bodyPartString);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
first.setAdapter(adapter);
second.setAdapter(adapter);
third.setAdapter(adapter);
}
public void setMondayThirdBodyPartExercises(String bodyPartString, Spinner first, Spinner second, Spinner third) {
List<String> data = populateSpinners(bodyPartString);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
first.setAdapter(adapter);
second.setAdapter(adapter);
third.setAdapter(adapter);
}
I want to change this line:
List<String> data = populateSpinners(bodyPartString);
I think it will be better when I call this method three times, and everything will be populated just by one method, instead of three different ones.
java sql android database
java sql android database
New contributor
New contributor
edited 8 mins ago
Jamal♦
30.2k11115226
30.2k11115226
New contributor
asked 10 hours ago
Tymbar
11
11
New contributor
New contributor
1
What's this app for? Tell us, and make that the title of the question — see How to Ask. Is this an online programming exercise or something? If so, please provide a link in addition to the description.
– 200_success
9 hours ago
I've edited post. :)
– Tymbar
6 hours ago
add a comment |
1
What's this app for? Tell us, and make that the title of the question — see How to Ask. Is this an online programming exercise or something? If so, please provide a link in addition to the description.
– 200_success
9 hours ago
I've edited post. :)
– Tymbar
6 hours ago
1
1
What's this app for? Tell us, and make that the title of the question — see How to Ask. Is this an online programming exercise or something? If so, please provide a link in addition to the description.
– 200_success
9 hours ago
What's this app for? Tell us, and make that the title of the question — see How to Ask. Is this an online programming exercise or something? If so, please provide a link in addition to the description.
– 200_success
9 hours ago
I've edited post. :)
– Tymbar
6 hours ago
I've edited post. :)
– Tymbar
6 hours ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Tymbar is a new contributor. Be nice, and check out our Code of Conduct.
Tymbar is a new contributor. Be nice, and check out our Code of Conduct.
Tymbar is a new contributor. Be nice, and check out our Code of Conduct.
Tymbar is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f208396%2fgym-application%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
What's this app for? Tell us, and make that the title of the question — see How to Ask. Is this an online programming exercise or something? If so, please provide a link in addition to the description.
– 200_success
9 hours ago
I've edited post. :)
– Tymbar
6 hours ago