用于从android

时间:2015-05-09 11:30:38

标签: android android-viewpager

我在做什么:

  1. 我有ViewPager,我将图片添加到ImageView 我创建的每个View
  2. 同时我为其设置TAG
  3. 我正在使用Activities
  4. 我想做什么:

    1. 在运行时,当我点击我想要的特定视图时 我在标记中为单击的适配器视图选择的值
    2. 如何实现此目标
    3. 当前代码:

      public class AdptAtomicSongGallery extends PagerAdapter {
              // Declare Variables
              Context context;
              LayoutInflater inflater;
              String godName;
              LinkedList<LinkedHashMap<String, String>> arrLst;
              LinkedHashMap<String, String> map;
      
              public AdptAtomicSongGallery(Context context, LinkedList<LinkedHashMap<String, String>> arrLst) {
                  this.context = context;
                  this.arrLst=arrLst;
              }
      
              @Override
              public int getCount() {
                  return arrLst.size();
              }
      
              @Override
              public boolean isViewFromObject(View view, Object object) {
                  return view == ((LinearLayout) object);
              }
      
      
      
      
              @Override
              public Object instantiateItem(ViewGroup container, int position) {
      
                  LinearLayout selFavGodsContainer;
      
                  LinkedHashMap<String, String> map=arrLst.get(position);
      
                  inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                  View itemView = inflater.inflate(R.layout.adpt_atomic_song_gallery, container,false);
      
                  txtSongNameId= (TextView) itemView.findViewById(R.id.txtSongNameId);
      
                  txtSongNameId.setTag(<!-----Myvalue---->)
      
                      }
                  });*/
      
                  // Add viewpager_item.xml to ViewPager
                  ((ViewPager) container).addView(itemView);
      
                  return itemView;
      
      
      }
      

1 个答案:

答案 0 :(得分:0)

如果我总结一切。如果用户点击了视图,您想要一个onClick事件,并且您想要txtSongNameId的标记值吗?

如果是的话。只需将onClickListener设置为itemView

itemView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        //you can get the txtSongNameId view like this here:
        (TextView) v.findViewById(R.id.txtSongNameId);
        //or you declare it final outside and use it like these here:
        txtSongNameId.getTag()
    }
});