[Android][ViewPager OnItemClickListener] - ViewPager Click OnItemClickListener
2019. 3. 29. 13:29ㆍPrograming/Android / Java
https://stackoverflow.com/questions/16350987/viewpager-onitemclicklistener
There is no OnItemClick callback method for ViewPager. If you want click events on each page then you'll have to build your listener into the page content within your Adapter.
something like this:
@Override public Object instantiateItem(View collection, final int pos) { //have to make final so we can see it inside of onClick() LayoutInflater inflater = (LayoutInflater) collection.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View page = inflater.inflate(R.layout.YOUR_PAGE, null); page.setOnClickListener(new OnClickListener(){ public void onClick(View v){ //this will log the page number that was click Log.i("TAG", "This page was clicked: " + pos); } }); ((ViewPager) collection).addView(page, 0); return page; }
exactly what you need will depend a bit on what else you are doing inside of instantiateItem()
which you haven't posted so I can't give you a more specific answer.
'Programing > Android / Java' 카테고리의 다른 글
[Android][Proguard] glide proguard (0) | 2019.05.05 |
---|---|
[Android][Proguard] appcompat-v7 proguard (0) | 2019.05.05 |
[Android Studio] How to rename the package name in an android studio? (안드로이드 스튜디오에서 패키지명 변경) (0) | 2019.03.19 |
[Android Studio] Remove all unused resources from an android project (0) | 2019.03.13 |
[Android/안드로이드] 손 쉬운 DEBUG Log 관리 방법 (0) | 2019.03.11 |