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

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

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

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
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,864
6 votes
Accepted

Code for sorting items in recyclerView

You're right that the duplicate code in the sorters looks bad. To solve this, each sorter should only define the compare function, and all the rest should be done by the enum class. Or not even this. ...
Roland Illig's user avatar
  • 21.3k
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,802
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.5k
5 votes
Accepted

Getting location using LiveData and FusedLocationProviderClient

Let me explain how to work with LiveData - ViewModel and Activity. Right now your ...
Akshay Chordiya's user avatar
5 votes
Accepted

Kotlin text validation

First of all, make attention - your code twice convert and check value. Suppose it's not efficient. Another tiny problem - 1280 and 1500 values is not change prefs.mtuSize… My code: ...
Victor Dmitrienko's user avatar
5 votes
Accepted

My Android app is really slow when getting simple data from PHP

When approaching optimization problems (and it kinda is one as you want to make a call faster) its generally best to first make sure that you understand exactly what is happening so when in doubt - ...
Azahe's user avatar
  • 265
5 votes

Android - A way to show/hide loader without writting false/true in every viewmodelScope.launch

If I interpret it correctly, you can basically wrap everything in a single method, and pass it a lambda: ...
Simon Forsberg's user avatar
4 votes

Listview from SQLite

One way you can improve this is by writing a data source class that does all your database access, instead of putting it inside the SQLiteOpenHelper. Leave that class to just creating and updating the ...
AdamMc331's user avatar
  • 383
4 votes
Accepted

Simple Timed Cache by Wrapping HashMap

Small code duplication The two constructors of DataCache have duplicated code: ...
Tunaki's user avatar
  • 9,243

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