Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Simplifying code to understand the code

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all!

Just as a quick back-story, I've been a graphic designer for 15 years and a web developer for 6 years now. I've taught myself a ton of web languages, but I'm finally making the jump to Java (for Android specifically). I can write most of a program using javascript/jQuery, but I know that Java and javascript are not the same! So, I am getting stuck in my own head.

I have this code (below) that I've written in android studio. It works, but I feel like there has to be a better/easier way.



Here's what it looks like:


Now, in javascript, I know I could write this same thing in 4 lines (with a few extra lines of CSS




So, I'm trying to get this mental "key" where I can start associating things. Is there a better way of writing these fake checkboxes? Can I style a checkbox to look like those buttons and let the default behavior work? Where do I need to go with this?

Thanks!
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Wow, that is indeed some horrible copy-and-paste code, and you could indeed do that in a much better way. For example, instead of making 16 variables for the 16 buttons you could put them all in an array, and then loop over the array, and then you wouldn't have to have 16 copies of the code that follows - you'd just have that once, inside the loop.
 
Nathan Grealish
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great Idea. I will start looking into Java Arrays. I know there has to be a better way, but I don't even know what to search for when it comes to Java!
 
Onion rings are vegetable donuts. Taste this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic