Posts by ramaral • 44,197 points
1,060 posts
-
10
votes5
answers1775
viewsA: Why is it bad practice to have int attributes?
In relation to "It’s bad practice to have attributes int(public),...." I do not see why, how much can be questioned if having public fields in general is good. The case presented has nothing to do…
-
1
votes2
answers1497
viewsA: How to open the Calculator using Intent?
Must use a Intent together with the startActivity method(); From what can be read in the documentation, to launch the calculator Intent shall indicate the category CATEGORY_APP_CALCULATOR: Intent…
-
4
votes1
answer1109
viewsA: Split(), using | (pipe) as separator, does not correctly separate the text
split() receives as parameter a regex, as | has a special function(is a meta-character) in regex it is not being considered as separator character. To ensure that the | is properly interpreted needs…
-
1
votes1
answer80
viewsA: Problem adding spinner to my form
Pass the code that initializes the spinner Adapter into the onCreateView() First get a reference to a Context to use in ArrayAdapter.createFromResource(): private Context contex; @Override public…
-
5
votes1
answer1352
viewsA: How to call the startActivity() method in an Adapter?
startActivity() is a class method Context, in order to use it you must have access to an instance of that class. To have a Context available on your Adapter declare a builder who receives it: public…
-
2
votes1
answer152
viewsA: Background with two colors
In XML I don’t know if it’s possible. In Java, one possible way is to create a Shape and build a Shapedrawable with her. Doistriangulosdrawable.java public class DoisTriangulosDrawable extends…
-
2
votes2
answers159
viewsA: How to pass the answer received by Volley to a Global variable?
I think what you want is for this class to communicate the result to the class that uses it. The use of global variables is not recommended, there are other ways to get what you want. One usual way…
-
2
votes1
answer379
viewsA: Progress Bar with Asynctask and multiple download links
To make it work, file_length, in int progress = (int) total * 100 / file_length would have to be the sum of the lengths of all images. This would require that, before reading the images, you have to…
-
9
votes2
answers4510
viewsA: What is the difference between Activity, Fragmentactivity and Fragment?
Both the Activity like the Fragment are components that provide a graphical interface (UI), to allow the user to interact with the application. The fundamental difference is that a Fragment needs an…
-
1
votes1
answer238
viewsA: How to obtain Arraylist from Listview?
In the Productosadapter create a method that returns the list of products: public ArrayList<Produtos> getProdutos(){ return produtos; } In the onClick() button use it as follows: Button…
-
1
votes1
answer226
viewsA: Update Seekbar as it plays the audio
Code 1: Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { mySeekBar.setProgress(mp.getCurrentPosition()); } }, 1000); It does not do what you want…
-
9
votes2
answers6247
viewsA: How to get the current date/time, independent of the device?
If you have access to internet can obtain the current date/time using a Public NTP Time Server. Since access to the service is a network operation it will have to be done in a thread other than…
-
10
votes3
answers617
viewsA: Create temporary lock on the app
You need to implement something that allows the application to know if it is blocked or not. This information can, as the regmoraes said, be stored in Shared Preferences. The question now is how to…
-
2
votes2
answers1687
viewsA: How to decrease the size of the text in a Listview?
Listview is a visual representation of data coming from a data source. Data is converted to Views using an Adapter. I think you must be wearing one Arrayadapter, together with the View…
-
3
votes1
answer78
viewsA: Single ring value
I think what you’re looking for is a Universally Unique Identifier (UUID). UUID is a 128-bit number which in its canonical form is expressed by 32 hexadecimal digits, divided into five groups…
-
6
votes1
answer1601
viewsA: Gps or antenna triangulation - How to know the accuracy of the location?
After getting a Location can use the method getAccuracy() to obtain the estimated accuracy in metres of that location. The estimated accuracy is defined as the 68% radius of confidence: if you draw…
-
1
votes1
answer341
viewsA: How to create events dynamically? C#
The value passed to the parameter sender of the method CalculaPasso() contains the Control that launched the event. Change the method this way: private void CalculaPasso(object sender,…
-
2
votes1
answer129
viewsA: Why does that line of code make me wrong?
There is no Overload for the method SQLiteDatabase.openOrCreateDatabase() with that signature. Use SQLiteDatabase.openOrCreateDatabase("BaseDados", null); which is the equivalent of…
-
8
votes1
answer70
viewsA: Property access modifier C#
The first form: public string Codigo { get; private set; } declares a property of public reading and private writing. The second form: public string Codigo { get; } declares a property readonly…
-
4
votes2
answers498
viewsA: Service versus Broadcastreceiver
The documentation defines Service as follows: A Service is an application component that can perform long operations and does not provide a user interface. Another application component can launch a…
-
2
votes1
answer54
viewsA: Remove child from an Expandedlistview
Include these two methods in the class Subcategoriaexpandabled pter. public void removerSubCategorias(int groupPosition) { mCollection.get(mList.get(groupPosition)).clear(); notifyDataSetChanged();…
-
2
votes1
answer344
viewsA: How to change the source of an image control from a Resourcedictionary
Via code you can access Resources declared/defined in a Control in two ways: 1 - Using the property Resources semaforo.Source = (BitmapImage) Control.Resources["semaforoVerde"]; 2 - Using the method…
-
3
votes1
answer31
viewsA: How to create a Merged "Resourcedictionaries"
Create a file shaman with the declaration of Resourcedictionary: <ResourceDictionary <SolidColorBrush x:Key="texto" Color="Yellow"/> <SolidColorBrush x:Key="texto1"…
-
12
votes2
answers381
viewsQ: Java 8 "default method" versus C# "extend method"
Java 8 introduces the concept of "standard method" to allow adding new features to an interface. C# provides "extension methods" that allow "adding" methods(features) to existing types. Taking into…
-
1
votes2
answers90
viewsA: Update all table records with Sqlitedatabase.update()
If you want to change all the records then you should not set the clause WHERE. The method update() has 4 parameters that from left to right are: 1 - String: Name of table to change. 2 -…
-
1
votes1
answer320
viewsA: Use a layout folder for more than one size
The reason is simple, see what it says to documentation: Be Aware that, when the Android system Picks which Resources to use at Runtime, it uses Certain Logic to determine the "best matching"…
-
11
votes1
answer2979
viewsA: "java.lang.Securityexception: Permission Denial" on Android 6 Marshmallow (API 23)
As of version 6.0 (API level 23), permissions considered "dangerous"(Dangerous Permissions) are validated during the execution of the application and not when installing. This does not invalidate…
-
2
votes1
answer113
viewsA: Set Linear background layout from String variable
It is possible to obtain the id of a drawable thus: int id = context.getResources() .getIdentifier(fundo, "drawable", context.getPackageName()); Obtained the id use setBackgroundResource():…
-
5
votes3
answers1666
viewsA: Rename gitignore.txt to . gitignore
Through explorer it is not possible to rename a file so that it has only extension, it is considered as having no name, which is not allowed. The solution is to open a command window and use the…
-
3
votes1
answer498
viewsA: Pass the execution of a particular method to Swingworker as argument
If the methods you want to run on doInBackground() had all the same signature the solution would be to declare an interface and pass it in the constructor of a class inherited from Swingworker.…
-
2
votes1
answer1152
viewsA: How to use a Spinner in a Alertdialog?
Needs to create a Arrayadapter make the call from string-array with the Spinner. The class Arrayadapter has the static method createFromResource() which creates a Adapter from a string-array.…
-
2
votes1
answer126
viewsA: How to eliminate extra space formed in a Linearlayout when creating Imageview via code?
Initially I thought it was a problem of layout but not. The image is being resized when it is assigned to Imageview, however its limits(Bounds) keep the original dimensions, making the Layout which…
-
7
votes1
answer425
viewsA: Why does the image get distorted (doesn’t maintain the proportions) in Imageview?
Substitute image.setBackgroundResource(rid); for image.setImageResource(rid); setBackgroundResource() assigns the image to background of view causing her to "stretch" in order to fill it all. In…
-
7
votes1
answer186
viewsA: Methods that require return even having Void in "signature"
void is the keyword used to indicate that a method does not return anything. In turn Void is a class, so, following the rules, the compiler forces something to be returned. Void is the version…
-
5
votes1
answer705
viewsA: How to update Listviem after deleting an item?
The Arraylist that the Adapter usa is not directly connected to the database: changes made to the database are not automatically passed on to the Array. Before using notifyDataSetChanged() these…
-
2
votes2
answers4441
viewsA: How to set space between buttons on Android?
In addition to the buttons you will need to use a view "empty"(1) to represent the spaces before, between and after each button. Attribute is used layout_weight to scale spaces equally.…
-
4
votes1
answer656
viewsA: Return onPostExecute() String
Declare an interface in the class Loginbackground: public interface OnLoginCompletedListener{ void onLoginCompleted(String result); } Add an instance variable: private OnLoginCompletedListener…
-
10
votes1
answer4596
viewsA: What is the difference between Appcompatactivity and Activity?
The difference is that the Appcompactactivity allows, using the support library, use the Actionbar(entered into the API level 11) in applications from the API level 7. After revision 22.1 a support…
-
0
votes1
answer133
viewsA: Imageview shows the image rotated by 90 degrees
Through the Picasso API you can access Bitmap after the load using the method Transform() of Requestcreator. Create a class that implements the interface Transformation: public class…
-
1
votes1
answer123
viewsA: Run Android method when application is terminated
If android destroy the process(by need to free memory for example), onDestroy() is not called and the same applies to onStop() for pre-HONEYCOMB applications.. To ensure that the file is sent do so…
-
2
votes1
answer54
viewsA: Check that Simulated Locations are active
From API18 to class Location provides the method isFromMockProvider() returning true if the location originates from the mock Provider. To know if simulated locations are active use preview…
-
4
votes1
answer213
viewsA: Method imageView.getDrawable() launches Nullpointerexception
The method image.getDrawable() is returning null, hence the NullPointerException You have to assign the image to Imageview through the attribute android:src and not the attribute android:background.…
-
1
votes3
answers1124
viewsA: how to show data from a sharedPreferences in a Listactivity
To get all stored values use the method getAll() of Sharedpreferences: Map<String,?> map = prefs.getAll(); For a list of values use: List<Value> list = new…
-
4
votes1
answer133
viewsA: How to dim the size of a Blob image?
You can decrease the dimensions of an image using the Bitmapfactory.Options passed to Bitmapfactory.decodeByteArray(). Write an auxiliary method to calculate the value of…
-
2
votes1
answer280
viewsA: Why is Broadcastreceiver called several times and always with the same "extra"?
This behavior has two causes: The Broadcastreceveir is being called several times because it is being logged by each message sent. The fact that only the latter is treated is due to the fact that…
-
2
votes2
answers822
viewsA: How to store images in an Android vector?
Don’t keep the pictures, keep your Resource Id using a int[]: int[] imagensIds = { R.drawable.image1, R.drawable.image2, R.drawable.image3 }; You can pass all images to a method:…
-
8
votes1
answer112
viewsA: What is the purpose of "&" in the generic type statement?
The type of parameter a generic type can handle can be limited by using the word extends(Bounded Type Parameters). The constraint is made by indicating the class it extends and/or interfaces it…
-
0
votes1
answer66
viewsA: Strange behavior of Basedapter on android
For what it gives me to realize you have not two list but only one. Having two variables with different names on their own does not guarantee that their value is different. In this part of the code…
-
5
votes2
answers4930
viewsA: What is the difference between Math.Random and java.util.Random?
The first difference is that Math.() is a static method of the class Math, while java.util. is a class. In this respect the advantage of Math. about java.util. it is not necessary to create an…
-
3
votes2
answers176
viewsA: How, by clicking on the notification, delete the notification and do not open the application?
So that the notification does not launch any Activity(Intent) when clicked create the Pendigintent, passed to the method setContentIntent() of Notificationcompat.Builder, as follows: PendingIntent…