Skip to content

Commit 89cf02f

Browse files
authored
Merge pull request #3 from smhdk/master
current fragment position listener added
2 parents 25bcf9d + 771c456 commit 89cf02f

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

.idea/modules.xml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/hololo/tutorial/sample/MainActivity.java

+5
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ public void finishTutorial() {
2828
Toast.makeText(this, "Tutorial finished", Toast.LENGTH_SHORT).show();
2929
finish();
3030
}
31+
32+
@Override
33+
public void currentFragmentPosition(int position) {
34+
Toast.makeText(this,"Position : " + position,Toast.LENGTH_SHORT).show();
35+
}
3136
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.hololo.tutorial.library;
2+
3+
public interface CurrentFragmentListener {
4+
void currentFragmentPosition(int position);
5+
}

library/src/main/java/com/hololo/tutorial/library/TutorialActivity.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.util.ArrayList;
2323
import java.util.List;
2424

25-
public class TutorialActivity extends AppCompatActivity implements View.OnClickListener {
25+
public abstract class TutorialActivity extends AppCompatActivity implements View.OnClickListener,CurrentFragmentListener {
2626

2727
private List<Step> steps;
2828
private StepPagerAdapter adapter;
@@ -32,6 +32,7 @@ public class TutorialActivity extends AppCompatActivity implements View.OnClickL
3232
private LinearLayout indicatorLayout;
3333
private FrameLayout containerLayout;
3434
private RelativeLayout buttonContainer;
35+
private CurrentFragmentListener currentFragmentListener;
3536

3637
private int currentItem;
3738

@@ -43,7 +44,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
4344
setTheme(R.style.TutorialStyle);
4445
super.onCreate(savedInstanceState);
4546
setContentView(R.layout.activity_tutorial);
46-
47+
currentFragmentListener = this;
4748
init();
4849
}
4950

@@ -74,6 +75,7 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse
7475
@Override
7576
public void onPageSelected(int position) {
7677
currentItem = position;
78+
currentFragmentListener.currentFragmentPosition(position);
7779
controlPosition(position);
7880
}
7981

@@ -279,4 +281,6 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
279281
changeFragment(true);
280282
}
281283
}
284+
285+
282286
}

0 commit comments

Comments
 (0)