As the name implies, global variables are variables that can be called in the entire class or in multiple functions. They are also called external variables. Local variables are variables that can be accessed in a specific procedure or function. It is easy to declare a variable, but when it comes to using it, it is not as simple as imagined. As for me, I often define global variables for use, but because of this, I define global variables. It also takes a lot of detours. When using Adapter, it is usually used with listView, because a listView basically has a layout of listView items. The following scenario is: there is an ImageView in each item. When I click on an item, I need to change the background color of the ImageView of the item or change it to another background image. At this time, a situation may occur that you clearly click on the first item, but you will find that the image of the third or second item has also changed. This is because you define a global variable. The code part is as follows:
In the above part, ImageView is a global variable. At this time, we need to define ImageView as a local variable.
This means that each Item has an ImageView. Another case is when you are making a shopping cart, you can click the plus and minus icons to change the number of items in the shopping cart. When you define the number num, you must also define it as a local variable. It would be better if you can use ViewHolder. |
<<: Android animation - cute candle blowing animation
>>: How to debug Android Framework?
If social media is the best way out for self-medi...
Fried foods have a crispy texture and pleasant ar...
In 2015, everyone started their own business, and...
Contents of this article: 1. How to break through...
When the "lifeline" on the Holter monit...
The staple food of many families in my country is...
Recently, the China Development Research Foundati...
The second round of patent war between Nokia and ...
Ma Ge Education - High-end Go language million co...
Maximize the acquisition of target users Acquisit...
[[145849]] In October 2013, my partner and I were...
On the 19th of last month, Son Masayoshi predicte...
The mobile Internet is moving from online applica...
"This year and next year will be the first y...
A new side business with huge profits, can you ma...