Posts by Leonardo Lima • 3,541 points
120 posts
-
3
votes1
answer83
viewsA: Android - Run function with seconds delay
You can use postDelayed: final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { Intent it = new Intent(MainActivity.this, SecondActivity.class);…
-
10
votes2
answers214
viewsA: What is the difference of var between Kotlin and Java?
var in Java came to reduce the verbosity of the language a little. Compiler makes type inference and prevents you from having to repeat type in some situations. Instead of writing:…
-
6
votes1
answer678
viewsA: How to know which Activity prior to the current Activity was called?
Using getCallingActivity(): If you start Activity with startActivityForResult, the method can be used getCallingActivity().getClassName(): private void startRegistroActivity() { Intent intent = new…
-
5
votes1
answer409
viewsA: Browse Hashmap with equal values
There are various forms, one of them being: Map<String, String> map = new HashMap<>(); map.put("1", "a"); map.put("2", "b"); map.put("3", "c"); map.put("4", "d"); map.put("5", "a");…
javaanswered Leonardo Lima 3,541 -
0
votes1
answer437
viewsA: pass parameters on a request in the retrofit
It is one of the first examples of documentation: @GET("group/{id}/users") Call<List<User>> groupList(@Path("id") int groupId); In your case: @GET("posts/{page}") Call<ModelJson[]>…
-
1
votes2
answers678
viewsA: What is the most efficient way to take information from any website and use it in an Android APP?
The most efficient way is to use a webservice. But since we don’t live in a perfect world, not always using a webservice is an option. In these cases you can use a library like the jsoup to scroll…
-
4
votes2
answers64
viewsA: Android - Open Random Activity
Random r = new Random(); int randomIndex = r.nextInt(5); // Index aleatorio de 0 a 4 Class<?>[] activities = new Class<?>[]{ Activity1.class, Activity2.class, Activity3.class,…
-
0
votes2
answers517
viewsA: Understanding the use of Generics in an abstract DAO Hibernate class
These will be types declared by the classes that will extend your DAO. Suppose you create a concrete DAO to work with an entity Book. He should be declared to be foma-like: public class BookDao…
-
1
votes1
answer194
viewsA: Method Invocation 'notify' may Produce 'java.lang.Nullpointexception'
This happens because the method getSystemService can return null. It is stated as follows (note the annotation @Nullable): public abstract @Nullable Object getSystemService(@ServiceName @NonNull…
androidanswered Leonardo Lima 3,541 -
1
votes2
answers100
viewsA: Networkonmainthreadexception error while recovering local IP from device
NetworkOnMainThreadException means that you tried to access a network resource on the main thread, which would cause UI blocking. One of the ways around this is by using a Asynctask, that will…
-
0
votes1
answer170
viewsA: subclass does not incorporate super class method
This is the standard behavior of language. Note that compel a subclass calling the super is considered an anti-standard in some languages. This article (in English) by Martin Fowler talks about the…
-
2
votes2
answers653
viewsA: How the.setOnClickListener(view -> method() item works)
The syntax in question is a lambda, syntax introduced in Java 8, explained in detail in this answer. Write this in Java 8: holder.moreButton.setOnClickListener(view -> updateItem(position)); It’s…
-
3
votes1
answer50
viewsA: Is it possible to simplify the Runnable command on an Android function?
Android Studio 3 supports some features of Java 8. You can enable this by adding the following lines in the build.Radle: android { ... compileOptions { sourceCompatibility JavaVersion.VERSION_1_8…
-
1
votes1
answer282
viewsA: Nullpointerexception when using setText for a Textview in Fragment
The views bind in Fragments is different from activities, according to the documentation. You should invoke: @Override public void onCreate(Bundle bundle) { LayoutInflater inflater =…
-
1
votes1
answer103
viewsA: Problems adding Jsonobject to Jsonarray
According to the documentation, the JsonArray represents a json array immutable. That is, once built, it cannot be modified. Instead of working with the JsonArray directly, use the JsonArrayBuilder:…
-
4
votes1
answer462
viewsA: Retrofit: Could not locate Responsebody converter for
Retrofit itself does not [de]serialize JSON. It delegates this to converters. So, when building the Retrofit object, you must pass the convert of your preference. They support Jackson, which is the…
-
2
votes1
answer82
viewsA: Kotlin + RX Observer without Anonymous
In the first example you showed, there are three past (and not one Observer). Overload is being invoked with the signature: subscribe(Consumer<? super T> onNext, Consumer<? super…
-
0
votes1
answer77
viewsA: file reading with scanner
The problem is that you try to access an index that doesn’t necessarily exist (name). You can do: //separa os campos entre as virgulas de cada linha String[] valoresEntreVirgulas =…
-
1
votes1
answer269
viewsA: 3 new user post questions with spring boot
1 - Best form is very relative. There are n ways to do this, each with a different purpose. If what you’ve done serves you, keep it the way it is. 2 - It is not being serialized because it is a…
-
3
votes1
answer290
viewsA: Generate an APK on a server
Yes, it is possible to do. Two possible approaches are: Approach 1: Configuration via Gradle You can create fields in Gradle and use them in the app. Even, these values can be passed as parameter…
-
1
votes2
answers219
viewsA: Is it possible to call a method within another instance?
You can pass a function to be executed when the button is clicked. In its static method class: fun buildDialog(context: Context, action: () -> Unit) { AlertDialog.Builder(context)…
-
0
votes1
answer40
viewsA: Add "filter" to "logger" for the entire application
You need to get the root logger: Logger rootLogger = LogManager.getLogManager().getLogger("");
-
0
votes1
answer134
viewsA: Recyclerview with JSON analysis
Your problem is reading the JSON. You are considering the array ITEMS is in the first object of the hierarchy, when in fact it is in the second. JSONObject jsonObject = new JSONObject(response);…
-
0
votes1
answer89
viewsA: MAINTAIN ACTIVITY BY MINIMIZING
When you are working with multiple activities, one way to solve this problem is to have an "empty" Activity as the initial. It would only contain a logic to check whether the user is logged in or…
-
0
votes3
answers48
viewsA: How to store which Navigation Drawe item I selected
One option is to use Sharedpreferences android. It is a mechanism for storing key-values. In the documentation you have some examples of how to use this class. When the user clicks on an item in the…
-
1
votes2
answers927
viewsA: Android Studio does not recognize images
To reference the images in the folder drawable, the correct is to use R.drawable.recurso
-
1
votes1
answer237
viewsA: How to convert an object to Kotlin of type Any! to another one that is possible to access the fields?
I would recommend you to understand what the library does in Java (reading the documentation), what are the guys she works with, then transpose to Kotlin. According to the documentation, you are…
-
1
votes1
answer72
viewsA: A function run infinitely in Servlet
You can use a ServletContextListener together with a ScheduledExecutorService. The ServletContextListener will be called when your application is initialized and finished. The…
-
4
votes2
answers162
viewsA: How to pass data from one button switch to another acivity?
The way to start the ColetarActivity is wrong. You should not instantiate a class Activity manually. The correct would be something like: Intent intent = new Intent(this, ColetarActivity.class);…
-
1
votes1
answer225
viewsA: Stackoverflowerror Retrofit With Basic Authentication
If the login password is not filled in, you invoke the same method createService(Class, String, String) again, infinitely. This causes the pile to burst. You need to rethink your logic at this…
-
1
votes1
answer212
viewsA: Java Stream converter Map<String, Obj> to List<Obj>
I believe the operator you want is the flatMap: List<LogLine> foo = logMap.entrySet().stream() .filter(map -> map.getValue().size() > parameters.getThreshold()) .flatMap(map ->…
-
1
votes1
answer205
viewsA: Download svg image to present in Imageview of Android as?
The Glide, with some adjustments and with the help of Androidsvg, supports SVG loading. You have an example in their repository which shows how. I will play the current code for posteriority: Add…
-
1
votes1
answer22
viewsA: Donwgrade from API 23 to 21
Yes, it is perfectly possible to diminiur the minSdkVersion for an app already published. Google Play makes no restrictions on this. Before making this migration, I recommend testing your app on…
androidanswered Leonardo Lima 3,541 -
0
votes1
answer47
viewsA: onNext on Observer is never called
This is the standard behavior of the toList() operator, which causes some confusion. As explained in Javadoc, he needs the upstream signal the onComplete to issue the list. In the diagram it is also…
rxjavaanswered Leonardo Lima 3,541 -
1
votes1
answer121
viewsA: How to make two Retrofit chain calls with Rxjava?
I believe in your case it’s best to do inside the chain, not subscribe. Use the operator flatMap: val restApi = retrofit.create(RestAPI::class.java) restApi.searchDoc("language", "title_query")…
-
1
votes1
answer127
viewsA: Manage android library versions
Using dynamic versions is a feature of Gradle, and is documented on their website: If the dependency is declared as a Dynamic version (like 1.+), Gradle will resolve this to the Newest available…
-
1
votes1
answer434
viewsA: Difficulty generating a JSON object in the correct order
According to the specification of JSON: An Object is an unordered Collection of zero or more name/value pairs, Where a name is a string and a value is a string, number, Boolean, null, Object, or…
-
1
votes1
answer203
viewsA: How to use Rxandroid?
By your explanation and your final question I see two scenarios. And without seeing your code just to make abstract examples, so come on. First scenario: Observables working with methods To pass…
-
1
votes1
answer110
viewsA: Project preview in android studio
You are in preview mode Project. Click the arrow above the file listing and select Android to return to summary visualization.…
-
2
votes1
answer427
viewsA: Problems making call using Retrofit on Android
Gson is failing to convert the answer to the informed type. According to your JSON, you must create a class that involves the list of products: public class RespostaProduto { private int total;…
-
2
votes1
answer83
viewsA: Strange Error On Android
java.lang.Thread.run(Thread.java:841) Caused by: java.lang.Runtimeexception: Can’t create Handler Inside thread that has not called Looper.prepare() at android.os.Handler. (Handler.java:200) at…
androidanswered Leonardo Lima 3,541 -
2
votes1
answer67
viewsA: ERROR: this - cannot be Applied to
On the line: SendMail sm = new SendMail(this,email,subject,message); You are trying to call a constructor that does not exist. You must create one that accepts the same parameters that are being…
-
1
votes1
answer2918
viewsA: How do I use Optional.ofNullable() in this example?
Considering the following implementation of the class Dados, that may have no phone: public class Dados { private String telefone; public Dados(String telefone) { this.telefone = telefone; } public…
-
1
votes2
answers841
viewsA: Retrieve and calculate programmatically generated Edittext values
The average has to be calculated outside the loop: Double total = 0.0; for (int i = 0; i < listEdit.size(); i++) { String texto = listEdit.get(i).getText().toString(); if (!texto.isEmpty()) {…
-
0
votes1
answer96
viewsA: Working with Tomcat + Eclipse + Sublimetext (Frontend)
I would start by running the application without the eclipse. You probably use Maven or Gradle in the project. Both tools offer plugins (Maven | Gradle) to deploy a War with a simple command in the…
-
2
votes2
answers197
viewsA: How do I know if it’s past midnight or a new day has begun?
date_current.getTime() == 0 will only return true when midnight of the day January 1, 1970 (epoch). The simplest way to check the hours is by using a Calendar. date_current =…
androidanswered Leonardo Lima 3,541 -
1
votes1
answer680
viewsA: Gson Library Changing useful. Date
When serializing to JSON, you end up losing the millisecond information. If you print the variable dataNoFormatoJson, you will see that she has a date in the format Oct 18, 2017 10:41:59 AM. By…
-
1
votes1
answer356
viewsA: Monitor Webview url
You can use a Webviewclient to intercept some events. webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) {…
-
3
votes1
answer141
viewsA: Increase/Decrease Seekbar progress with Button action?
Just use the methods setProgress and getProgress of SeekBar: bt_MaisHomem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) {…
-
0
votes1
answer119
viewsA: How to get JSON values that Okhttp generated?
You can use the Httplogginginterceptor. After including the library in your project, simply add it as a Interceptor in his OkHttpClient: HttpLoggingInterceptor logging = new…