Skip to content

Limit Decimal Places in Android EditText

I’m trying to write an app that helps you manage your finances. I’m using an EditText Field where the user can specify an amount of money. I set the inputType to numberDecimal which works fine, except that this allows people to enter numbers such as 123.122 which is not perfect for money. Is there…

ResultSetMetaData getScale returns 0

I have a table called RATE_HISTORY with a field called RATE. The RATE field has scale 18. I am using ResultsetMetaData to get meta-data of columns in this table on Oracle 11.2. I execute the following …

What is the simplest way to draw in Java?

What is the simplest way to draw in Java? This doesn’t work and I have no idea how to get anything to appear. Answer Easiest way: You simply need to extend JPanel and override the paintComponent method of the panel. I’d like to reiterate that you should not be overriding the paint method. Here is …

Intersection and union of ArrayLists in Java

Are there any methods to do so? I was looking but couldn’t find any. Another question: I need these methods so I can filter files. Some are AND filters and some are OR filters (like in set theory), so I need to filter according to all files and the unite/intersects ArrayLists that holds those files. Sho…

Adding whitespace in Java

There is a class trim() to remove white spaces, how about adding/padding? Note: ” ” is not the solution. Answer I think you are talking about padding strings with spaces. One way to do this is with string format codes. For example, if you want to pad a string to a certain length with spaces, use s…

Set running time limit on a method in java

I have a method that returns a String. Is it possible that after a certain time, if threshold is excedeed for that method, to return some specific string? Answer The Guava library has a very nice TimeLimiter that lets you do this on any method that’s defined by an interface. It can generate a proxy for …