Posts by ramaral • 44,197 points
1,060 posts
-
1
votes1
answer622
viewsA: How to change the width and height of a Relativelayout by Java code
It is not normally necessary/advisable to assign absolute values to android:layout_width and android:layout_height of layouts. The normal is to assign match_parent or wrap-content. However you can…
-
1
votes1
answer830
viewsA: Elevation Button is not showing Shadow
When assigning a background to the button this will lose some of its features. Among them are elevation and animation when clicked. On the other hand, even without assigning a background it is not…
-
1
votes1
answer2462
viewsA: Adjust Image/Bitmap to Imageview or adjust Imageview to Image/Bitmap
When defining absolute values for android:layout_width and android:layout_height Imageview will be presented with these dimensions. If you want the Imageview fits the dimensions of layout that it…
-
12
votes2
answers134
viewsA: Problem with return of a Java method
His method, due to if, has two possible paths for execution to follow. 1st path, if the condition is true if(getNumLugares() < getNumDePassageiros()) nomes.add(nome); 2nd path, if the condition…
-
7
votes1
answer430
viewsA: Random always returning the same number
The class Random uses an algorithm to generate the sequence of (pseudo)random numbers. This sequence is started on the basis of a value called Seed. Different values generate different sequences.…
-
0
votes2
answers123
viewsA: How to apply attributes of a parent Viewgroup to child in android studio?
To my knowledge, it will only be possible to implement this behavior in a class inherited from Textview. public class TextViewWithParentTopMargin extends android.support.v7.widget.AppCompatTextView…
-
5
votes2
answers261
viewsA: Warning:(40, 5) Do not place Android context classes in Static Fields; this is a memory Leak (and also breaks Instant Run)
You have a problem leaving it the way it is? Yes you have. This will/may cause the memory used by the application to grow progressively. This happens because part of the memory allocated in this…
-
2
votes1
answer655
viewsA: How to associate/open mp3 files in raw folder?
This happens because when copying the file to the raw folder you associated it as text or something like that. Anyway Androidstudio doesn’t have an internal music player. What you should do is, in…
-
3
votes1
answer496
viewsA: How to find out if an Imageview has an informed photo
Depending on the method you used to assign the photo to Imageview use if(imageView.getDrawable() != null) or if(imageView.getBackground() != null)…
-
1
votes1
answer352
viewsA: How to change Alertdialog buttons?
To close Alertdialog use the method Dismiss(). This requires a reference to Alertdialog at the time you declare the OnClickListener textview R.id.botao_negativo. Thus, you must create Alertdialog…
-
3
votes1
answer68
viewsA: What is the difference between a Toolbar and another view?
Toolbar is indeed a type of View, more properly a type of Viewgroup: java.lang.Object ↳ android.view.View ↳ android.view.ViewGroup ↳ android.support.v7.widget.Toolbar As you can see in his…
-
2
votes1
answer265
viewsA: setOnItemClickListener does not work in Custom Adapter
When the layout of Listview items contains Views that react to "clicks" or receive phocus, the "click", made available by listView.setOnItemClickListener, is disabled. To enable it must include…
-
2
votes1
answer1354
viewsA: How to change the color of the Statusbar
To change the color of the Statusbar you must use the attribute android:statusBarColor. <style name="AppTheme" parent="android:Theme.Material.Light"> <item…
-
1
votes2
answers1000
viewsA: How to get a list of values common to two lists with LINQ?
I think what you want is intercession between the two lists Use the method Intersect(). It returns a Ienumerable with the elements that exist simultaneously in both lists lista1 =…
-
2
votes1
answer843
viewsA: Transforming image into array of bytes
Use this method: public byte[] convertImageViewToByteArray(ImageView image){ Bitmap bitmap = ((BitmapDrawable)image.getDrawable()).getBitmap(); ByteArrayOutputStream stream = new…
-
2
votes1
answer161
viewsA: Error:(44) No Resource Identifier found for attribute 'srcCompat' in package 'my package name'
Apparently the mistake is in app:srcCompat="@android:drawable/ic_menu_revert". With the information provided, I cannot know why. For now, you can solve the problem by replacing…
-
2
votes2
answers593
viewsA: How to prevent the user from typing in Edittext, but allow clicking on it to open a Datepicker?
Add the following to Edittext: android:focusable="false" This will prevent Edittext from receiving phocus, not allowing you to type in it. Alternatively use a Textview instead of Edittext. For…
-
3
votes2
answers574
viewsA: How can I change the Edittext selection and pointer color?
I think that it is not possible to change, dynamically (after Edittext has been created), via java. Via XML, create a style: <style name="SelectionColor"> <item…
-
0
votes1
answer141
viewsA: Null appears instead of the recovered name
Appears "null" because, when the array frases is built, the field nomedoHumano is null. What the array stores in position 0 is the result of the expression nomedoHumano + "se você traçar metas…
-
2
votes2
answers131
viewsA: Assign values to a Alertdialog views
To get references to Alertdialog layout views you have to use the method findViewById() of this layout and not of the Activity. Instead of ImageView img = (ImageView) findViewById(R.id.ima); use…
-
3
votes1
answer57
viewsA: Is it possible to create a different app version for each android version?
It is possible, even if it is creating a project for each version. The main problem with this approach is code repetition., This problem can be avoided using another approach: Build variants. Build…
-
0
votes1
answer387
viewsA: Tablerow line division - Layout
Tablerow should be used inside Tablelayout, if it is not behaving like a horizontal Linearlayout. Tablerow being a layout(extends Linearlayout) can contain any view, including other layout type. So,…
-
5
votes1
answer321
viewsA: How to cut part of a bitmap?
Use the static method createBitmap() of the Bitmap class: Bitmap createBitmap (Bitmap source, int x, int y, int width, int height) In your case use it like this: Bitmap croppedBitmap =…
-
7
votes1
answer406
viewsA: java.lang.Indexoutofboundsexception: Invalid index 4, size is 4
Error indicates you are trying to use an index outside the range. In this case you are using index 4 while the array only has 4 items. Note that index numbering starts at 0. The reason for this to…
-
1
votes1
answer1668
viewsA: index outside range c#
You are trying to assign a letter to a position that does not exist in Stringbuilder. To do this you must initialize Stringbuilder with a number of positions equal to the word you want to discover:…
-
26
votes1
answer2059
viewsQ: What are the coroutines?
What I’ve been given to understand is that it’s a new way of writing asynchronous code, allowing you to avoid blocking the thread. This leads me to assume that they are an alternative to class…
-
7
votes3
answers701
viewsA: What to do when the argument passed in the constructor is invalid?
The class shall be responsible for avoiding being instantiated in a non-valid state. Therefore, in the constructor, past values should be checked and an exception should be made if they are invalid.…
-
5
votes2
answers88
viewsA: How do I detect that the headset has been plugged in?
Yes, it is necessary to create a Broadcastreceiver but it must be registered explicitly, through Context.registerReceiver(), and not merely stated in Androidmanifest.xml. In relation to…
-
2
votes1
answer301
viewsA: An instrumentation test is an integration test?
Integration tests are intended to verify that the result of the interaction between the different parts/components of the application is as expected. The instrumental tests aim to simulate user…
-
6
votes2
answers168
viewsA: What is Pushnotification really?
Push Notification is a system of sending information to a customer without explicitly requesting it. Unlike the Pull Notifications, where the client has to request the information from the server,…
-
2
votes3
answers47
viewsA: Datetime does not update on Console.Writeline
Datetime is not a "clock" that changes its representation over time. Datetime is immutable, it represents the instant it was created. To do what you want you must create a Datetime object whenever…
-
0
votes1
answer118
views -
0
votes1
answer32
viewsA: Crash app when trying to save a file using Objectoutputstream
The Objectoutputstream can only write to an Outputstream objects that implement the java.io.Serializable interface. Thus, the class Class and all its properties, which are not primitive types, have…
-
2
votes1
answer302
viewsA: Pass list to another Activity
If you just want to pass the selected items to another Activity, store them in one ArrayList<Produto>. Place this array in Intent with intent.putExtra(). The class Product has to implement the…
-
3
votes2
answers1240
viewsA: What is the purpose of the Recyclerview.Adapter class when using Recyclerview?
What is the purpose of the Customadapter class when using Recyclerview? A Recyclerview must be able to visually present a variety of data types and in different ways. For this to be possible to…
-
11
votes1
answer1772
viewsA: What is Viewholder Pattern?
What is Viewholder Pattern? Approach used to store a set of views so they can be efficiently accessed and reused when needed. The purpose of the class Viewholder is to save the views. What is the…
-
0
votes1
answer184
viewsA: Search in listview does not show the corresponding item
The reason for this is because you are using the position of the clicked item as index to get the music in the array resID. The correspondence between position and index is only correct when…
-
1
votes1
answer75
viewsA: Gridview - Items repeating randomly
Yes, you’re right. This is because views (line layout) are repurposed. The problem with your code is that you are only assigning values to views when the layout is null(if (convertView == null)).…
-
2
votes1
answer659
viewsA: Save status of a Checkbox
I suppose the reason of the field selected of the Statevo class. In the Adapter use it to save and recover Checkbox status. The recover part you already did. Missing the save part, which should be…
-
1
votes2
answers100
viewsA: Do you need to use Appcompat and Support Design libraries when the minimum API is 21?
Not, if using only existing features in (up) Loolipop. Yes, if you want to use new features and methods available in versions after Loolipop.
-
3
votes1
answer77
viewsA: How to tell whom a class will extend at runtime?
It is not possible for a class at one time to inherit from A and at another time to inherit from B. If I understand what you want, use one of these approaches: Bridge Design Pattern If the classes…
-
1
votes2
answers21
viewsA: What is this error "D/TAG: Return...: [Lcom.example.Gustavo.domanda.Consultarpojo;@11c78941"
This is not an error, it is the string that represents the object. When you use an object of this form, implicit conversion to string, the return of the method is used toString() of that object. The…
-
0
votes1
answer323
viewsA: How to place line to split items in a Spinner?
What you should do is apply the style <style name="spinnerDropDownItemStyle" parent="Widget.AppCompat.ListView.DropDown"> <item name="android:dividerHeight">2dip</item> <item…
-
1
votes2
answers920
viewsA: How to know which Fragment is being displayed
You can use the method getFragments() of Fragmentmanager to get a list of all the Ragments added to it. List<Fragment> fragments = fragMgr.getFragments(); It’s not completely clear in your…
-
23
votes2
answers4166
viewsA: What is the difference between array and matrix?
This is more a mathematical concept than programming. Just as a square is a particular case of a quadrilateral, a array is a particular case of a matrix: it is a matrix with only one dimension.…
-
0
votes1
answer78
viewsA: Set the initial time of a Chonometer with the text of a textView
The value in Textview is a string that represents minutes and seconds. To use it, as the starting value of Chonometer, you have to convert it to milliseconds. Create a method for conversion: private…
-
0
votes2
answers963
viewsA: Scrollview with Images and Linearlayout
Scrollview only accepts a View/Layout inside it. I can’t be sure, but it seems to me that in your case, he should be the first: <?xml version="1.0" encoding="utf-8"?> <ScrollView…
-
1
votes1
answer1496
viewsA: How to check if file exists in the application directory in the internal storage?
The code you’re using is to access the storage external. If you want to get the path to the root of the storage intern must use File getFilesDir(). To get the full path to a file name, stored in…
-
6
votes3
answers171
viewsQ: Is it possible to have properties other than those generated automatically in a data class?
Kotlin allows you to simplify the creation of what in Java we call POJO: data class Person(val firstName: String, val lastName: String) With this we get a class with the getter for all variables…
-
8
votes2
answers308
viewsQ: Why does Kotlin use a way of declaring functions and variables other than "traditional"?
Traditionally the return type and variable type are indicated at the beginning, before the name: public int soma(int a, int b){ return a + b; } In Kotlin he is named after: fun sum(a: Int, b: Int):…