How do you get the resource name through the interface onItemClickListener?



  • I have GridViewthere are several images. With help OnItemClickListener and method onItemClick() I can get it. position The clicked element, but it's not good for me because one element can be in different places. How do I get the name of the resource of the clicked element through View?

    gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v,
            int position, long id) {
            //тут нужно получить имя ресурса
        }
    });
    


  • Apparently. View However, the ID resource that is in the process cannot be obtained View by direct means View)

    Appropriation View Resource value, record this value in the tag:

     imageView.setImageResource( R.drawable.imageN);
     imageView.setTag(R.drawable.imageN);
    

    Then you can get the meaning of that. Viewthat passes the bell:

    public void onItemClick(AdapterView<?> parent, View v,
                                int position, long id) {
             int id = v.getTag();
        }
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2