Android - Add multiple tags to ImageView

爱⌒轻易说出口 提交于 2019-12-06 14:41:08

问题


I am new at android programming and want to create an application in which I can add multiple custom tags to an displayed Image. I researched a bit and found out aboutsetTag() method of ImageView. But it does mention if it allows multiple tagging. Also is there any way that those tags to remain visible (along with appropriate tagged position) on the image?

Will I require an SurfaceView or GridView for this?

Sources :

Android Image View

android-Image View set Tag

Thank you.


回答1:


Instead of looking for multiple tags you can use a class MyTag as follows to tag more than one data to a view

public class MyTag
{
   int  int_Tag;
   String  string_Tag;
   MyClass  myclass_obj_Tag;


    public MyTag()
    {
      int_Tag=0;
      string_Tag=null;
      myclass_obj_Tag=null;
    }

    public MyTag(int i,String s,MyClass m)
    {
      int_Tag=i;
      string_Tag=s;
      myclass_obj_Tag=m;
    }


}

create an object of this class and assign values to variables in object

MyTag myTag=new MyTag(1,"string_tag",myClass_obj);
iv.setTag(myTag);

just give it a try,I have used this method,




回答2:


You can add any object as a tag. If the data you're adding need more data, the simplest way would be to add a Hashtable as the tag. Then add all the key/value pairs you want to that Hashtable.



来源:https://stackoverflow.com/questions/23533229/android-add-multiple-tags-to-imageview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!