ViewPager
,我将图片添加到ImageView
我创建的每个View
TAG
值Activities
当前代码:
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;
}
答案 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()
}
});