Android: Use the setTag () and getTag () Methods of View
We usually use the findViewById () method to obtain the View control we want to use. However, in addition to this method, we can also use the setTag (Onbect) in the View) add an extra data to the View and use getTag () to obtain the corresponding View. The setTag () and getTag () methods are often used to p
Write a custom adapter to bind the listview. When rewriting getview, I found that the online reference code used the settag () and gettag () functions. Baidu could not find the answer, google will find it: P
The settag (onbect) in the view indicates that an extra data is added to the view. In the future, you can use gettag () to retrieve this data.
You can use multiple buttons to add a listener. Each butto
This is useful when you need to use the adapter custom control display mode.The adapter has a getview method. You can use settag to cache the view to facilitate multiple reuse.
Public View getview (INT position, view convertview, viewgroup parent ){Viewholder VL;
If (convertview = NULL ){Layoutinflater Inflater = (layoutinflater) mwidgetsswitchapp. Getsystemservice (context. layout_inflater_service );Convertview = Inflater. Inflate (R. layout. app_gallery_item, null );Vl = new viewholder ();Vl.
Title: Method Settag (), Gettag () play a role in viewWhy I find such a problem, the main reason is that I encountered when learning Viewholder, then only know how to use. At Google, I found a good explanation on StackOverflow. Hence the translation of one or two.Source Address: Http://stackoverflow.com/questions/5291726/what-is-the-main-purpose-of-settag-gettag-methods-of-viewExplanation:For example, you c
Settag ()/gettag ()
Settag (Onbect) In view adds an extra set of data to the view, which can be taken out later with Gettag ().
You can use multiple button to add a listener, each button setting a different Settag. The listener is gettag to tell which button is being pressed.
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.view.View;
Import
first we need to know what the Settag method is, he is a label to the View object, the tag can be anything, we set him up as an object here, Because we abstract the elements of Vlist2.xml into a class Viewholder, using the Settag, this tag isViewholder a property of an object after it is instantiated.we then forViewholderinstantiated ObjectsHolderthe operation, all becauseJavareference mechanism that has survived and changedConvertviewthe content, and not every time is going toNewone. We're just
Android setTag () and getTag (), and set multiple setTag ()
First, we need to know what the setTag method is.
Tags
Unlike IDs, tags are not used to identify views. tags are essentially an extra piece of information that can be associated with a view. they are most often used as a convenience to store data related to views in the views themselves rather than by putting them in a separate structure.
Unlike the ID, a Tag indicates a view. In essence,
Android: Use setTag and getTag of View
1. Used to differentiate many similar views
For example:
button1.setOnClickListener(new OnClickListener ... );button2.setOnClickListener(new OnClickListener ... );
They may execute similar logic, but you must set two independent OnClick events for the two buttons respectively,
public void onClick(View v) { doAction(1); // 1 for button1, 2 for button2, etc.}
This is because onClick has only one View paramete
Reprinted: http://www.apkbus.com/android-13264-1-1.html
Write a custom adapter to bind the listview. When rewriting getview, you will find that the online reference code is useful to the settag () and gettag () functions.
The settag (onbect) in the view indicates that an extra data is added to the view. In the future, you can use gettag () to retrieve this data.
You can use multiple buttons to add a listen
What is the main purpose of setTag () getTag () methods of View ?, SettaggettagExample: Method setTag () and getTag () play a role in View
The main reason why I found such a problem is that I only knew how to use it when I learned ViewHolder. At google, I found stackoverflow had a good explanation. Translation 2.
Source Address: http://stackoverflow.com/questions/5291726/what-is-the-main-purpose-of-settag-
); Holder.text2.setText (DATA.TEXT2); Holder.longtext.setText (Data.longtext); returnConvertview; }}The acquisition of Convertview involves the recycle problem of the ListView, not the focus of this article. Here is the main view of the implementation of Viewholder. The implementation of Viewholder relies on the view provided by the Settag and Gettag two methods, in order to facilitate understanding of the two methods and the
In Android, Settag (Object) is able to add a special tag to a view and then use Gettag () to get the tag.用处1:多个button设置不同tag,通过tag区分new OnClickListener() { publicvoidonClick(View v) {//获取当前view对应的数字 int cellId = (Integer) v.getTag(); cellClicked(cellId, v); } } View v; for (int020; i++) { v = findViewById(cellIDs[i]); v.setOnClickListener(listener); v.setTag(i); }用法2:在adapter中的getview实现回收的convertView的复用(这代码高亮搞不好,总是出问题)@Override public View
The settag (onbect) in the view indicates that an extra data is added to the view. In the future, you can use gettag () to retrieve this data.
You can use multiple buttons to add a listener. Each button has a different settag. The listener uses gettag to identify which button is pressed.
Import Android. App. activity; Import Android. OS. Bundle; Import Android. View. vie
This is useful when you need to use the adapter custom control display mode.The adapter has a getview method. You can use settag to cache the view to facilitate multiple reuse.
Public View getview (INT position, view convertview, viewgroup parent ){Viewholder VL;
If (convertview = NULL ){Layoutinflater Inflater = (layoutinflater) mwidgetsswitchapp. Getsystemservice (context. layout_inflater_service );Convertview = Inflater. Inflate (R. layout. app_gallery_item, null );Vl = new viewholder ();Vl.
Settag is a Android of the View a useful method in a class,In the same class, it is convenient to access data without building a database,It also saves memory more than sharepreference.Settag ( Object tag) method is relatively simpleLike whatTextView tvexecutor = (TextView) Findviewbyid (R.ID.T);Tvexecutor.settag(selectedusermap);This SelectedusermapCan make mapIt can also be the object of LinkedlistYou can store a variety of temporary data, but you can't call it a storage method.In the same cla
for recursion around the world // However, this is not required here, only when the gettag () method is called, it indicates that you need to put a view in a region. Therefore, put the opened method in gettag () and call // to mark mtagflag = true ;} // save location information in the tag of celllayout settag (cellinfo );
Note that the usage of cells in celllayout is calculated here. At the same time, th
to using Log directly, a TAG needs to be defined. A common method is to define a static String constant TAG for each log class and assign a value to the class name. If you forget to modify the TAG during refactoring, you may be confused when viewing the log. Of course, there are also a lot of people who will map it easily and directly use System. out. println (str); for output.When I read VolleyLog two days ago, I learned a new method,
private static String
name.Assume. When refactoring, forget to change the tag so that you may be confused when looking at log.Of course, there are also very many people who will be easy to figure. Directly with System.out.println (str); output.When I looked at Volleylog two days ago, I learned a new way. Private StaticStringGettag() {stacktraceelement[] trace =NewThrowable (). Fillinstacktrace (). Getstacktrace (); String Callingclass =""; for(inti =2; i if(!clazz.equals (Logutil.class)) {Callingcl
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.