Hot answers tagged

16 votes
Accepted

Selecting an enum for a payment transaction

You're using the wrong tool for the job. If there's ever going to be a loan that I will pay an amount to every week for 2 years, you're gonna have to write a script to generate the code for you, ...
Pimgd's user avatar
  • 22.3k
10 votes
Accepted

Find index of double number delimiter

The problems with the first approach ...
Tunaki's user avatar
  • 9,243
10 votes
Accepted

SlotMachine game as first Android app

Clear state rather than restart You use this function to restart the game: public void recreateGame(View v) { finish(); startActivity(getIntent()); } ...
janos's user avatar
  • 111k
10 votes
Accepted

Recyclerview Adapter for weather app - Makes API calls for each item

First issue You're calling the weather API on every OnBindViewHolder(), which means it will get called for each visible row, and on new rows entering, or re-...
Benito Bertoli's user avatar
8 votes

Android Activity with a RecyclerView inflated by a big ArrayList

I don't know much about Android so I will comment on a more general concern with the code. There is something I find makes your code difficult to read for me: I don't speak Italian. In fact, most ...
Phrancis's user avatar
  • 20.4k
7 votes
Accepted

Android utils class

I'm looking at this class and I'm confused. The reason why is that I'm doing web programming so a dialog can be asked on different sessions. In that case this class is useless. In stead of holding ...
chillworld's user avatar
  • 3,872
7 votes
Accepted

Recycler view with cursor adapter

First of all CursorAdapter is not designed for use with a RecyclerView. You are trying to hack something in there that would ...
Simon's user avatar
  • 186
7 votes
Accepted

Login UI for an Android app

Using an AsyncTask instead would be much better. You've got many callbacks to the UI thread, all of this you could do in the post execute method instead: ...
Aritz's user avatar
  • 355
6 votes

Reuse a base class [Activity] handler in all sub classes for background work

You make some assumptions about your window in this line: mHandler = getWindow().getDecorView().getHandler(); As mentioned by the Activity docs for getWindow() ...
Vogel612's user avatar
  • 25.2k
6 votes
Accepted

Calculate sum of all the items in array list?

Naming s is a bad parameter name. If there's nothing better, use editable. Avoid abbreviations. ...
Eric Stein's user avatar
  • 6,494
6 votes

Android unit converter

What you need is to use a common base unit that all your other units converts to. For example, let's take a look at this: ...
Simon Forsberg's user avatar
6 votes

Selecting an enum for a payment transaction

There is a better way indeed, which is to have the installments value as an attribute of each enumeration value. An as example, we can simply consider 2 of those ...
Tunaki's user avatar
  • 9,243
6 votes
Accepted

Sudoku with Android

Singletons You have made your GameEngine and SudokuChecker as singletons, meaning that you are preventing multiple instances ...
Simon Forsberg's user avatar
6 votes
Accepted

Android splash screen

Using a thread for a SplashScreen is fine, however a much cleaner solution would to use a Handler as below... ...
Mekon's user avatar
  • 156
6 votes

Does this method contain multiple implementations?

Seemed fine at first, then I took another look... The validation function displays the error message? I'm sorry, but that's indeed a violation of SRP. You'd be better off returning a ...
Pimgd's user avatar
  • 22.3k
6 votes
Accepted

Validating an IP address and returning the reason it's invalid

Your code has three major errors that all the previous reviewers failed to spot. If I were a lecturer, I'd show your code to the students as an example why they should always use libraries, even doing ...
Rok Kralj's user avatar
  • 184
6 votes

Updating positions of enemies every frame

Some things you could try: Unless the waypoints change position, the objects will continue in the same direction each frame. This means you don't have to recalculate ...
Trent Bartlem's user avatar
6 votes

SlotMachine game as first Android app

// Do the math ... Doesn't provide much explanation. I would instead say: ...
Dair's user avatar
  • 5,824
5 votes
Accepted

Randomly Generate Planets

Bug? ...
Pimgd's user avatar
  • 22.3k
5 votes

Android app with config and customization classes

Public class, private Interface? I'm pretty confused by this setup. The meaning is always trying working towards the most highest object( this case interface) possible. I'm thinking that you created ...
chillworld's user avatar
  • 3,872
5 votes

Iterate faster through the Android file system and find specific files using java multithreading

Have you read the docs of CopyOnWriteArrayList? As the name suggest CopyOnWriteArrayList creates copy of underlying ArrayList with every mutation operation e.g. add or set. Normally ...
janos's user avatar
  • 111k
5 votes
Accepted

Speech reorganization helper class

Returning boolean A pattern if (condition) return true; return false is to be avoided. return condition; ...
vnp's user avatar
  • 55.9k
5 votes
Accepted

Determine differences between two Strings, for use in undo/redo feature

These are my suggestions: separate the string comparison algorithm from the technology (Parcelable). This will help you to test your algorithm without the burden of technology and increases ...
oopexpert's user avatar
  • 3,122
5 votes
Accepted

Searching two different elements in a same list

There's no problem with the performance. Java 8 filtering actually doesn't scan the whole stream, so the processing will be done only until the first element meeting the predicate is hit. So you're ...
Aritz's user avatar
  • 355
5 votes

Android splash screen

The best way to do splash screens is creating a style and adding a drawable (the layout of the page) to this style; afterwards setting the activity theme the style you just created. drawable/...
Punpuf's user avatar
  • 151
5 votes
Accepted

Simple Background Thread Worker Class (follow-up)

Escape of this on the constructor When you call start the thread may receive the current object (this) and start execution ...
Bruno Costa's user avatar
  • 5,566
5 votes
Accepted

Reading complete contact information in Android

Use AsyncQueryHandler, a helper class to help make handling asynchronous ContentResolver queries easier. It basically wraps the ...
Amandeep Rohila's user avatar
5 votes
Accepted

Setting icons when a tab is selected

You check whether the index of the tab equals the position. If this is the case, use the selected icon, otherwise use the unselected one: ...
mtj's user avatar
  • 4,782
5 votes

Tic Tac Toe in Android

Favor enum values over magic values int c[][]; This holds the board and the numbers represent state. Consider ...
mdfst13's user avatar
  • 21.4k

Only top scored, non community-wiki answers of a minimum length are eligible