Displaying 21 spinners to select body parts











up vote
0
down vote

favorite












I just wanted to ask how can I make my code a bit shorter. As of now, I have way too much code in the class. The program should display about twenty one spinners. I know it's a lot, but in this layout, users have to create their own training plan for 3 training days. In every training day, user has to select up to three body parts (one body part - 3 spinners with exercises, it should look like that)



Monday:

Chest: -first exercise (spinner) -second exercise (spinner) -third exercise (spinner)

Triceps -first exercise (spinner) -second exercise (spinner) -third exercise (spinner) etc..


I've already filled spinners with exercises from database, but I want to make this class shorter because for filling my spinners (just Ctrl+C, Ctrl+V) I've written about 2400 lines of code where about 2000 it's just copied method, with changed adapter etc. Did can i make it shorter? Here's first method



public void setMondayFirstBodyPart_1() {

switch (mondayFirstBodyPartFirstExerciseString) {
case "shoulders": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Shoulders");
break;
}
case "chest": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Chest");
break;
}
case "back": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Back");
break;
}
case "biceps": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Biceps");
break;
}
case "triceps": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Triceps");
break;
}
case "forearm": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Forearm");
break;
}
case "stomach": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Stomach");
break;
}
case "legs": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Legs");
break;
}
case "calf": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Calf");
break;
}
}
}









share|improve this question
















bumped to the homepage by Community 15 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Welcome to Code Review. I suggest that you show more context, so that we can advise you properly. For example, what does the db code look like? See How to Ask.
    – 200_success
    Nov 10 at 21:27










  • Every case statement is the same except the setText parameter. So just extract the whole duplicated case statement in new method with just one parameter.
    – Ankit Soni
    Nov 10 at 21:29










  • @Ankit Soni - the List<String> data also gets different values depending on the case.
    – 0X0nosugar
    Nov 10 at 21:35










  • @0X0nosugar, you are right, my bad. Two parameters then, the db data list and text value.
    – Ankit Soni
    Nov 10 at 21:39















up vote
0
down vote

favorite












I just wanted to ask how can I make my code a bit shorter. As of now, I have way too much code in the class. The program should display about twenty one spinners. I know it's a lot, but in this layout, users have to create their own training plan for 3 training days. In every training day, user has to select up to three body parts (one body part - 3 spinners with exercises, it should look like that)



Monday:

Chest: -first exercise (spinner) -second exercise (spinner) -third exercise (spinner)

Triceps -first exercise (spinner) -second exercise (spinner) -third exercise (spinner) etc..


I've already filled spinners with exercises from database, but I want to make this class shorter because for filling my spinners (just Ctrl+C, Ctrl+V) I've written about 2400 lines of code where about 2000 it's just copied method, with changed adapter etc. Did can i make it shorter? Here's first method



public void setMondayFirstBodyPart_1() {

switch (mondayFirstBodyPartFirstExerciseString) {
case "shoulders": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Shoulders");
break;
}
case "chest": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Chest");
break;
}
case "back": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Back");
break;
}
case "biceps": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Biceps");
break;
}
case "triceps": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Triceps");
break;
}
case "forearm": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Forearm");
break;
}
case "stomach": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Stomach");
break;
}
case "legs": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Legs");
break;
}
case "calf": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Calf");
break;
}
}
}









share|improve this question
















bumped to the homepage by Community 15 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Welcome to Code Review. I suggest that you show more context, so that we can advise you properly. For example, what does the db code look like? See How to Ask.
    – 200_success
    Nov 10 at 21:27










  • Every case statement is the same except the setText parameter. So just extract the whole duplicated case statement in new method with just one parameter.
    – Ankit Soni
    Nov 10 at 21:29










  • @Ankit Soni - the List<String> data also gets different values depending on the case.
    – 0X0nosugar
    Nov 10 at 21:35










  • @0X0nosugar, you are right, my bad. Two parameters then, the db data list and text value.
    – Ankit Soni
    Nov 10 at 21:39













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I just wanted to ask how can I make my code a bit shorter. As of now, I have way too much code in the class. The program should display about twenty one spinners. I know it's a lot, but in this layout, users have to create their own training plan for 3 training days. In every training day, user has to select up to three body parts (one body part - 3 spinners with exercises, it should look like that)



Monday:

Chest: -first exercise (spinner) -second exercise (spinner) -third exercise (spinner)

Triceps -first exercise (spinner) -second exercise (spinner) -third exercise (spinner) etc..


I've already filled spinners with exercises from database, but I want to make this class shorter because for filling my spinners (just Ctrl+C, Ctrl+V) I've written about 2400 lines of code where about 2000 it's just copied method, with changed adapter etc. Did can i make it shorter? Here's first method



public void setMondayFirstBodyPart_1() {

switch (mondayFirstBodyPartFirstExerciseString) {
case "shoulders": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Shoulders");
break;
}
case "chest": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Chest");
break;
}
case "back": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Back");
break;
}
case "biceps": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Biceps");
break;
}
case "triceps": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Triceps");
break;
}
case "forearm": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Forearm");
break;
}
case "stomach": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Stomach");
break;
}
case "legs": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Legs");
break;
}
case "calf": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Calf");
break;
}
}
}









share|improve this question















I just wanted to ask how can I make my code a bit shorter. As of now, I have way too much code in the class. The program should display about twenty one spinners. I know it's a lot, but in this layout, users have to create their own training plan for 3 training days. In every training day, user has to select up to three body parts (one body part - 3 spinners with exercises, it should look like that)



Monday:

Chest: -first exercise (spinner) -second exercise (spinner) -third exercise (spinner)

Triceps -first exercise (spinner) -second exercise (spinner) -third exercise (spinner) etc..


I've already filled spinners with exercises from database, but I want to make this class shorter because for filling my spinners (just Ctrl+C, Ctrl+V) I've written about 2400 lines of code where about 2000 it's just copied method, with changed adapter etc. Did can i make it shorter? Here's first method



public void setMondayFirstBodyPart_1() {

switch (mondayFirstBodyPartFirstExerciseString) {
case "shoulders": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Shoulders");
break;
}
case "chest": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Chest");
break;
}
case "back": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Back");
break;
}
case "biceps": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Biceps");
break;
}
case "triceps": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Triceps");
break;
}
case "forearm": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Forearm");
break;
}
case "stomach": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Stomach");
break;
}
case "legs": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Legs");
break;
}
case "calf": {
List<String> 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);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText("Calf");
break;
}
}
}






java android sqlite






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 23:29









Stephen Rauch

3,76061530




3,76061530










asked Nov 10 at 21:21









user184370

1




1





bumped to the homepage by Community 15 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 15 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • Welcome to Code Review. I suggest that you show more context, so that we can advise you properly. For example, what does the db code look like? See How to Ask.
    – 200_success
    Nov 10 at 21:27










  • Every case statement is the same except the setText parameter. So just extract the whole duplicated case statement in new method with just one parameter.
    – Ankit Soni
    Nov 10 at 21:29










  • @Ankit Soni - the List<String> data also gets different values depending on the case.
    – 0X0nosugar
    Nov 10 at 21:35










  • @0X0nosugar, you are right, my bad. Two parameters then, the db data list and text value.
    – Ankit Soni
    Nov 10 at 21:39


















  • Welcome to Code Review. I suggest that you show more context, so that we can advise you properly. For example, what does the db code look like? See How to Ask.
    – 200_success
    Nov 10 at 21:27










  • Every case statement is the same except the setText parameter. So just extract the whole duplicated case statement in new method with just one parameter.
    – Ankit Soni
    Nov 10 at 21:29










  • @Ankit Soni - the List<String> data also gets different values depending on the case.
    – 0X0nosugar
    Nov 10 at 21:35










  • @0X0nosugar, you are right, my bad. Two parameters then, the db data list and text value.
    – Ankit Soni
    Nov 10 at 21:39
















Welcome to Code Review. I suggest that you show more context, so that we can advise you properly. For example, what does the db code look like? See How to Ask.
– 200_success
Nov 10 at 21:27




Welcome to Code Review. I suggest that you show more context, so that we can advise you properly. For example, what does the db code look like? See How to Ask.
– 200_success
Nov 10 at 21:27












Every case statement is the same except the setText parameter. So just extract the whole duplicated case statement in new method with just one parameter.
– Ankit Soni
Nov 10 at 21:29




Every case statement is the same except the setText parameter. So just extract the whole duplicated case statement in new method with just one parameter.
– Ankit Soni
Nov 10 at 21:29












@Ankit Soni - the List<String> data also gets different values depending on the case.
– 0X0nosugar
Nov 10 at 21:35




@Ankit Soni - the List<String> data also gets different values depending on the case.
– 0X0nosugar
Nov 10 at 21:35












@0X0nosugar, you are right, my bad. Two parameters then, the db data list and text value.
– Ankit Soni
Nov 10 at 21:39




@0X0nosugar, you are right, my bad. Two parameters then, the db data list and text value.
– Ankit Soni
Nov 10 at 21:39










2 Answers
2






active

oldest

votes

















up vote
0
down vote













I don't know of what type mondayFirstBodyPartFirstExercise currently is but maybe you could use polymorphism and add the behavior there. This would would put database logic into your entities though. (Active Record pattern)



public void setMondayFirstBodyPart_1() {
List<String> data = mondayFirstBodyPartFirstExercise.getData();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mondayFirstBodyPartFirstExercise.setAdapter(adapter);
mondayFirstBodyPartExerciseTV.setText(mondayFirstBodyPartFirstExercise.getBodyPartName());
}





share|improve this answer




























    up vote
    0
    down vote













    Let's take a look at one of the case blocks:



    case "shoulders": {
    List<String> 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);
    mondayFirstBodyPartFirstExercise.setAdapter(adapter);
    mondayFirstBodyPartExerciseTV.setText("Shoulders");
    break;
    }


    The only lines which depend directly on the selected body part are



    List<String> data = db.getShouldersData();


    and



    mondayFirstBodyPartExerciseTV.setText("Shoulders");


    So let's suppose you have a method findDataForBodyPart(String bodyPart) which will make the database call and return the data list (or an empty list if there is no data to be found). In addition to that, you need another method getNameOfBodyPart(String) which will take a String (e.g. "shoulders") and return the desired TextView text (e.g. "Shoulders").



    Then you can abbreviate your code as follows:



    public void setMondayFirstBodyPart_1() {
    List<String> data = findDataForBodyPart(mondayFirstBodyPartFirstExerciseString);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mondayFirstBodyPartFirstExercise.setAdapter(adapter);
    mondayFirstBodyPartExerciseTV.setText(getNameOfBodyPart(mondayFirstBodyPartFirstExerciseString));
    }


    You can avoid even more repetitions (this time of whole methods) if you pass the value of mondayFirstBodyPartFirstExerciseString as parameter into the method, together with the corresponding Spinner and TextView:



    public void setExerciseFor(String bodyPartString, Spinner exerciseSpinner, TextView exerciseTextView) {
    List<String> data = findDataForBodyPart(bodyPartString);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    exerciseSpinner.setAdapter(adapter);
    exerciseTextView.setText(getNameOfBodyPart(bodyPartString));
    }


    Please note that in order to suggest further improvements, we'd need to see more of your code.






    share|improve this answer























    • When adding additional information you should edit your answer instead of adding a comment. I have added that information to your post. Learn more about comments including when to comment and when not to in the Help Center page about Comments.
      – Sᴀᴍ Onᴇᴌᴀ
      Nov 11 at 11:06













    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "196"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207388%2fdisplaying-21-spinners-to-select-body-parts%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    I don't know of what type mondayFirstBodyPartFirstExercise currently is but maybe you could use polymorphism and add the behavior there. This would would put database logic into your entities though. (Active Record pattern)



    public void setMondayFirstBodyPart_1() {
    List<String> data = mondayFirstBodyPartFirstExercise.getData();
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mondayFirstBodyPartFirstExercise.setAdapter(adapter);
    mondayFirstBodyPartExerciseTV.setText(mondayFirstBodyPartFirstExercise.getBodyPartName());
    }





    share|improve this answer

























      up vote
      0
      down vote













      I don't know of what type mondayFirstBodyPartFirstExercise currently is but maybe you could use polymorphism and add the behavior there. This would would put database logic into your entities though. (Active Record pattern)



      public void setMondayFirstBodyPart_1() {
      List<String> data = mondayFirstBodyPartFirstExercise.getData();
      ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
      adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      mondayFirstBodyPartFirstExercise.setAdapter(adapter);
      mondayFirstBodyPartExerciseTV.setText(mondayFirstBodyPartFirstExercise.getBodyPartName());
      }





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        I don't know of what type mondayFirstBodyPartFirstExercise currently is but maybe you could use polymorphism and add the behavior there. This would would put database logic into your entities though. (Active Record pattern)



        public void setMondayFirstBodyPart_1() {
        List<String> data = mondayFirstBodyPartFirstExercise.getData();
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        mondayFirstBodyPartFirstExercise.setAdapter(adapter);
        mondayFirstBodyPartExerciseTV.setText(mondayFirstBodyPartFirstExercise.getBodyPartName());
        }





        share|improve this answer












        I don't know of what type mondayFirstBodyPartFirstExercise currently is but maybe you could use polymorphism and add the behavior there. This would would put database logic into your entities though. (Active Record pattern)



        public void setMondayFirstBodyPart_1() {
        List<String> data = mondayFirstBodyPartFirstExercise.getData();
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        mondayFirstBodyPartFirstExercise.setAdapter(adapter);
        mondayFirstBodyPartExerciseTV.setText(mondayFirstBodyPartFirstExercise.getBodyPartName());
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 1:26









        fap

        1615




        1615
























            up vote
            0
            down vote













            Let's take a look at one of the case blocks:



            case "shoulders": {
            List<String> 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);
            mondayFirstBodyPartFirstExercise.setAdapter(adapter);
            mondayFirstBodyPartExerciseTV.setText("Shoulders");
            break;
            }


            The only lines which depend directly on the selected body part are



            List<String> data = db.getShouldersData();


            and



            mondayFirstBodyPartExerciseTV.setText("Shoulders");


            So let's suppose you have a method findDataForBodyPart(String bodyPart) which will make the database call and return the data list (or an empty list if there is no data to be found). In addition to that, you need another method getNameOfBodyPart(String) which will take a String (e.g. "shoulders") and return the desired TextView text (e.g. "Shoulders").



            Then you can abbreviate your code as follows:



            public void setMondayFirstBodyPart_1() {
            List<String> data = findDataForBodyPart(mondayFirstBodyPartFirstExerciseString);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mondayFirstBodyPartFirstExercise.setAdapter(adapter);
            mondayFirstBodyPartExerciseTV.setText(getNameOfBodyPart(mondayFirstBodyPartFirstExerciseString));
            }


            You can avoid even more repetitions (this time of whole methods) if you pass the value of mondayFirstBodyPartFirstExerciseString as parameter into the method, together with the corresponding Spinner and TextView:



            public void setExerciseFor(String bodyPartString, Spinner exerciseSpinner, TextView exerciseTextView) {
            List<String> data = findDataForBodyPart(bodyPartString);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            exerciseSpinner.setAdapter(adapter);
            exerciseTextView.setText(getNameOfBodyPart(bodyPartString));
            }


            Please note that in order to suggest further improvements, we'd need to see more of your code.






            share|improve this answer























            • When adding additional information you should edit your answer instead of adding a comment. I have added that information to your post. Learn more about comments including when to comment and when not to in the Help Center page about Comments.
              – Sᴀᴍ Onᴇᴌᴀ
              Nov 11 at 11:06

















            up vote
            0
            down vote













            Let's take a look at one of the case blocks:



            case "shoulders": {
            List<String> 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);
            mondayFirstBodyPartFirstExercise.setAdapter(adapter);
            mondayFirstBodyPartExerciseTV.setText("Shoulders");
            break;
            }


            The only lines which depend directly on the selected body part are



            List<String> data = db.getShouldersData();


            and



            mondayFirstBodyPartExerciseTV.setText("Shoulders");


            So let's suppose you have a method findDataForBodyPart(String bodyPart) which will make the database call and return the data list (or an empty list if there is no data to be found). In addition to that, you need another method getNameOfBodyPart(String) which will take a String (e.g. "shoulders") and return the desired TextView text (e.g. "Shoulders").



            Then you can abbreviate your code as follows:



            public void setMondayFirstBodyPart_1() {
            List<String> data = findDataForBodyPart(mondayFirstBodyPartFirstExerciseString);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mondayFirstBodyPartFirstExercise.setAdapter(adapter);
            mondayFirstBodyPartExerciseTV.setText(getNameOfBodyPart(mondayFirstBodyPartFirstExerciseString));
            }


            You can avoid even more repetitions (this time of whole methods) if you pass the value of mondayFirstBodyPartFirstExerciseString as parameter into the method, together with the corresponding Spinner and TextView:



            public void setExerciseFor(String bodyPartString, Spinner exerciseSpinner, TextView exerciseTextView) {
            List<String> data = findDataForBodyPart(bodyPartString);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            exerciseSpinner.setAdapter(adapter);
            exerciseTextView.setText(getNameOfBodyPart(bodyPartString));
            }


            Please note that in order to suggest further improvements, we'd need to see more of your code.






            share|improve this answer























            • When adding additional information you should edit your answer instead of adding a comment. I have added that information to your post. Learn more about comments including when to comment and when not to in the Help Center page about Comments.
              – Sᴀᴍ Onᴇᴌᴀ
              Nov 11 at 11:06















            up vote
            0
            down vote










            up vote
            0
            down vote









            Let's take a look at one of the case blocks:



            case "shoulders": {
            List<String> 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);
            mondayFirstBodyPartFirstExercise.setAdapter(adapter);
            mondayFirstBodyPartExerciseTV.setText("Shoulders");
            break;
            }


            The only lines which depend directly on the selected body part are



            List<String> data = db.getShouldersData();


            and



            mondayFirstBodyPartExerciseTV.setText("Shoulders");


            So let's suppose you have a method findDataForBodyPart(String bodyPart) which will make the database call and return the data list (or an empty list if there is no data to be found). In addition to that, you need another method getNameOfBodyPart(String) which will take a String (e.g. "shoulders") and return the desired TextView text (e.g. "Shoulders").



            Then you can abbreviate your code as follows:



            public void setMondayFirstBodyPart_1() {
            List<String> data = findDataForBodyPart(mondayFirstBodyPartFirstExerciseString);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mondayFirstBodyPartFirstExercise.setAdapter(adapter);
            mondayFirstBodyPartExerciseTV.setText(getNameOfBodyPart(mondayFirstBodyPartFirstExerciseString));
            }


            You can avoid even more repetitions (this time of whole methods) if you pass the value of mondayFirstBodyPartFirstExerciseString as parameter into the method, together with the corresponding Spinner and TextView:



            public void setExerciseFor(String bodyPartString, Spinner exerciseSpinner, TextView exerciseTextView) {
            List<String> data = findDataForBodyPart(bodyPartString);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            exerciseSpinner.setAdapter(adapter);
            exerciseTextView.setText(getNameOfBodyPart(bodyPartString));
            }


            Please note that in order to suggest further improvements, we'd need to see more of your code.






            share|improve this answer














            Let's take a look at one of the case blocks:



            case "shoulders": {
            List<String> 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);
            mondayFirstBodyPartFirstExercise.setAdapter(adapter);
            mondayFirstBodyPartExerciseTV.setText("Shoulders");
            break;
            }


            The only lines which depend directly on the selected body part are



            List<String> data = db.getShouldersData();


            and



            mondayFirstBodyPartExerciseTV.setText("Shoulders");


            So let's suppose you have a method findDataForBodyPart(String bodyPart) which will make the database call and return the data list (or an empty list if there is no data to be found). In addition to that, you need another method getNameOfBodyPart(String) which will take a String (e.g. "shoulders") and return the desired TextView text (e.g. "Shoulders").



            Then you can abbreviate your code as follows:



            public void setMondayFirstBodyPart_1() {
            List<String> data = findDataForBodyPart(mondayFirstBodyPartFirstExerciseString);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mondayFirstBodyPartFirstExercise.setAdapter(adapter);
            mondayFirstBodyPartExerciseTV.setText(getNameOfBodyPart(mondayFirstBodyPartFirstExerciseString));
            }


            You can avoid even more repetitions (this time of whole methods) if you pass the value of mondayFirstBodyPartFirstExerciseString as parameter into the method, together with the corresponding Spinner and TextView:



            public void setExerciseFor(String bodyPartString, Spinner exerciseSpinner, TextView exerciseTextView) {
            List<String> data = findDataForBodyPart(bodyPartString);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            exerciseSpinner.setAdapter(adapter);
            exerciseTextView.setText(getNameOfBodyPart(bodyPartString));
            }


            Please note that in order to suggest further improvements, we'd need to see more of your code.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 11 at 11:04









            Sᴀᴍ Onᴇᴌᴀ

            8,09961751




            8,09961751










            answered Nov 10 at 22:15









            0X0nosugar

            1214




            1214












            • When adding additional information you should edit your answer instead of adding a comment. I have added that information to your post. Learn more about comments including when to comment and when not to in the Help Center page about Comments.
              – Sᴀᴍ Onᴇᴌᴀ
              Nov 11 at 11:06




















            • When adding additional information you should edit your answer instead of adding a comment. I have added that information to your post. Learn more about comments including when to comment and when not to in the Help Center page about Comments.
              – Sᴀᴍ Onᴇᴌᴀ
              Nov 11 at 11:06


















            When adding additional information you should edit your answer instead of adding a comment. I have added that information to your post. Learn more about comments including when to comment and when not to in the Help Center page about Comments.
            – Sᴀᴍ Onᴇᴌᴀ
            Nov 11 at 11:06






            When adding additional information you should edit your answer instead of adding a comment. I have added that information to your post. Learn more about comments including when to comment and when not to in the Help Center page about Comments.
            – Sᴀᴍ Onᴇᴌᴀ
            Nov 11 at 11:06




















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Code Review Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f207388%2fdisplaying-21-spinners-to-select-body-parts%23new-answer', 'question_page');
            }
            );

            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







            Popular posts from this blog

            Ellipse (mathématiques)

            Quarter-circle Tiles

            Mont Emei