How-to articles, tricks, and solutions about ANDROID

Android changing Floating Action Button color

To change the color of a Floating Action Button (FAB) in Android, you can use the setBackgroundTintList() method and pass it a color state list.

android on Text Change Listener

In Android, you can use a TextWatcher to listen for changes to the text in a TextView or EditText view.

Android SDK installation doesn't find JDK

If the Android SDK installation is unable to find the JDK (Java Development Kit), it could be because the JDK is not installed or is not installed in the default location.

Android Split string

To split a string in Android, you can use the split() method of the String class.

Converting a string to an integer on Android

To convert a string to an integer in Android, you can use the Integer.parseInt method.

Converting double to string

In Java, you can convert a double to a string using the Double.toString() method or the String.valueOf() method.

Download a file with Android, and showing the progress in a ProgressDialog

To download a file with Android and show the progress in a ProgressDialog, you can use the following steps:

Execution Failed for task :app:compileDebugJavaWithJavac in Android Studio

Execution failed for task :app:compileDebugJavaWithJavac is an error message that can occur when you are trying to build an Android project in Android Studio.

Extending from two classes

In Java, a class can only extend from one superclass (i.e., it can only have one direct parent class).

Failed to install android-sdk: "java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema"

The java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema error can occur if the required Java XML Binding (JAXB) classes are not present on the classpath.

Get a JSON object from a HTTP response

To get a JSON object from a HTTP response in Java, you can use the JSONObject class from the org.json library.

Getting java.net.SocketTimeoutException: Connection timed out in android

The java.net.SocketTimeoutException: Connection timed out error usually occurs when a client is trying to connect to a server, but the connection request is taking too long to complete.

GSON throwing "Expected BEGIN_OBJECT but was BEGIN_ARRAY"?

If GSON is throwing a JsonSyntaxException with the message "Expected BEGIN_OBJECT but was BEGIN_ARRAY", it means that you are trying to parse a JSON array as if it were a JSON object.

How can I fix 'android.os.NetworkOnMainThreadException'?

The android.os.NetworkOnMainThreadException is a runtime exception that is thrown when an application attempts to perform a networking operation on the main thread.

How can I generate random number in specific range in Android?

To generate a random number in a specific range in Android, you can use the nextInt method of the java.util.Random class.

How set background drawable programmatically in Android

To set a background drawable programmatically in Android, you can use the setBackgroundDrawable method of the View class.

How to call a method after a delay in Android

To call a method after a delay in Android, you can use the Handler class and the postDelayed() method. The postDelayed() method takes a Runnable and a delay in milliseconds as arguments, and it runs the Runnable after the specified delay.

How to call a SOAP web service on Android

To call a SOAP web service on Android, you can use the HttpURLConnection class to send an HTTP request to the web service and receive the response.

How to check certificate name and alias in keystore files?

To check the certificate name and alias in a keystore file, you can use the keytool utility that comes with the Java Development Kit (JDK).

How to check internet access on Android? InetAddress never times out

To check for internet access on Android, you can use the isReachable() method of the InetAddress class.

How to create JSON Object using String?

To create a JSON object from a string in Java, you can use the org.json library. Here's an example of how to do this:

How to create RecyclerView with multiple view types

To create a RecyclerView with multiple view types in Android, you will need to use a RecyclerView.Adapter that supports multiple view types.

How to decompile DEX into Java source code?

To decompile DEX (Dalvik Executable) files into Java source code, you can use a DEX decompiler such as JD-GUI or DEX2JAR.

How to get current location in Android

To get the current location in Android, you can use the LocationManager class and the LocationProvider interface.

1 2