Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use global variables and local variables in Android

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to use global variables and local variables in Android". In daily operation, I believe many people have doubts about how to use global variables and local variables in Android. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to use global variables and local variables in Android". Next, please follow the editor to study!

When using Adapter, that is, the adapter, the adapter is usually used with listView, because a listView will basically have an Item layout of listView. The following scenario is: there will be an ImageView in each Item. When I click on a certain item, I need to change the background color or change the background picture for the ImageView of that Item. One of the situations that may occur at this time is the first one that you clearly point out. You will find that the picture in the third or second item has also changed. This is because you define global variables. The code section is as follows:

Public class Adapter extends BaseAdapter {private ImageView img; public View getView (int position, View convertView, ViewGroup parent) {convertView = mInflater.inflate (R.layout.grouproomlistviewroomitem.null); img = (ImageView) convertView.findViewById (R.id.logo); return convertView;}}

In the above part, ImageView is a global variable. At this point, we need to define ImageView as a local variable.

Public class Adapter extends BaseAdapter {public View getView (int position, View convertView, ViewGroup parent) {convertView = mInflater.inflate (R.layout.grouproomlistviewroomitem.null); ImageView img = (ImageView) convertView.findViewById (R.id.logo); return convertView;}}

At this time, it means the ImageView in each Item. Another situation is that when making a shopping cart, you can click the add and subtract icon to change the number of items in the shopping cart. When you define a quantity num, it must also be defined as a local variable. It would be even better if you can use ViewHolder.

At this point, the study on "how to use global variables and local variables in Android" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report