【转】Android的setTag】的更多相关文章

转自: http://blog.csdn.net/brokge/article/details/8536906 setTag是android的view类中很有用的一个方法,可以用它来给空间附加一些信息,在很多场合下都得到妙用. setTag(Object tag)方法比较简单,这里主要谈一谈带两个参数的setTag方法. 官方的api文档中提到:“ The specified key should be an id declared in the resources of the applica…
前言 首先我们要知道setTag方法是干什么的,SDK解释为 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 th…
android在设计View类时,为了能储存一些辅助信息,设计一个一个setTag/getTag的方法.这让我想起在Winform设计中每个Control同样存在一个Tag. 今天要说的是我最近学习android遇见的setTag的坑.一般情况下我们只需要使用唯一参数的setTag方法.但有时我们需要存储多个数据,所以这个时候我们就需要使用带key的重载. 文档是描述:“ The specified key should be an id declared in the resources of…
(转自:http://www.cnblogs.com/topcoderliu/archive/2011/06/07/2074419.html) [自己经历:要getTag前提是要有setTag] setTag()/getTag() View中的setTag(Onbect)表示给View添加一个格外的数据,以后可以用getTag()将这个数据取出来. 可以用在多个Button添加一个监听器,每个Button都设置不同的setTag.这个监听器就通过getTag来分辨是哪个Button 被按下. i…
E/AndroidRuntime(19480): java.lang.IllegalArgumentException: The key must be an application-specific resource id.E/AndroidRuntime(19480): at android.view.View.setTag(View.java:15615) http://stackoverflow.com/questions/2859574/the-key-must-be-an-appli…
Adapter 有个getView方法,可以使用setTag把查找的view缓存起来方便多次重用 public View getView(int position, View convertView, ViewGroup parent) {       ViewHolder vh; if (convertView == null) {               LayoutInflater inflater = (LayoutInflater) mWidgetsSwitchApp       …
1.用于区分非常多类似的View 比如: button1.setOnClickListener(new OnClickListener ... ); button2.setOnClickListener(new OnClickListener ... ); 它们可能运行类似的逻辑,但你必须分别为两个Button设置两个独立的OnClick事件, public void onClick(View v) { doAction(1); // 1 for button1, 2 for button2,…
View中的setTag(Onbect)表示给View添加一个格外的数据,以后可以用getTag()将这个数据取出来. 可以用在多个Button添加一个监听器,每个Button都设置不同的setTag.这个监听器就通过getTag来分辨是哪个Button 被按下. import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; public…
首先我们要知道setTag方法是干什么的,SDK解释为 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 v…
1)在string.xml 文件中添加 <item tyoe="id" name = "tag_first" /> <item tyoe="id" name = "tag_send" /> <item tyoe="id" name = "tag_three" /> 已此类推 在使用的时候 View.setTag(R.id.tag_first, 数据);…