Skip to content

Commit 938c48f

Browse files
committed
added view to listener
1 parent a509bbe commit 938c48f

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
public class MainActivity extends TutorialActivity {
1414

1515
private View currentFragmentView;
16+
private int currentPosition;
1617

1718
@Override
1819
protected void onCreate(Bundle savedInstanceState) {
@@ -38,7 +39,8 @@ public void currentFragmentPosition(int position) {
3839
}
3940

4041
@Override
41-
public void currentFragmentView(View view) {
42+
public void currentFragmentView(View view, int position) {
4243
currentFragmentView = view;
44+
currentPosition = position;
4345
}
4446
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
public interface CurrentFragmentListener {
66
void currentFragmentPosition(int position);
77

8-
void currentFragmentView(View view);
8+
void currentFragmentView(View view, int position);
99
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@
1111
public class StepFragment extends StepView {
1212

1313
private static CurrentFragmentListener currentFragmentListener;
14+
private static int position = -1;
1415
private TextView title;
1516
private TextView content;
1617
private TextView summary;
1718
private ImageView imageView;
1819
private View layout;
1920

20-
static StepFragment createFragment(Step step, CurrentFragmentListener listener) {
21+
static StepFragment createFragment(Step step, CurrentFragmentListener listener, int pos) {
2122
StepFragment fragment = new StepFragment();
2223
Bundle bundle = new Bundle();
2324
bundle.putParcelable("step", step);
2425
fragment.setArguments(bundle);
26+
position = pos;
2527
currentFragmentListener = listener;
2628
return fragment;
2729
}
@@ -39,8 +41,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
3941
int layout = step.getViewType() > 0 ? step.getViewType() : R.layout.fragment_step;
4042

4143
View view = inflater.inflate(layout, container, false);
42-
43-
currentFragmentListener.currentFragmentView(view);
44+
currentFragmentListener.currentFragmentView(view, position);
4445
initViews(view);
4546
initData();
4647

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ public int getCount() {
2626
public Fragment getItem(int position) {
2727
Step step = stepList.get(position);
2828

29-
return StepFragment.createFragment(step, currentFragmentListener);
29+
return StepFragment.createFragment(step, currentFragmentListener, position);
3030
}
3131
}

0 commit comments

Comments
 (0)