Home > Mobile >  Writes viewpager by more than 2 pages will flash back, is this why?
Writes viewpager by more than 2 pages will flash back, is this why?

Time:10-06

Public class FragmentOne extends fragments implements Runnable {

Private ViewPager ViewPager. Private int [] gg=new int [] {R.m ipmap. Header_pic_ad1, R.m ipmap. Header_pic_ad2}; Private List ShowPager=new ArrayList (a); Private ViewGroup dotViewGroup; Private List DotView=new ArrayList (a); Private View View; Private Thread t;

1

2

3

4

5

6

7

Override
Public void onAttach (Context Context) {
Super. OnAttach (context);
}

@ Override public void onCreate (@ Nullable Bundle savedInstanceState) {super. OnCreate (savedInstanceState);

1

2

3

}

@ Override public void onActivityCreated (@ Nullable Bundle savedInstanceState) {super. OnActivityCreated (savedInstanceState); ViewPager=(viewPager) view. The findViewById (R.i d.s how_view); DotViewGroup=(ViewGroup) view. The findViewById (R.i d.d ot_layout); For (int I=0; I & lt; Gg. Length; I++) {ImageView v=new ImageView (getContext ()); V. etScaleType (ImageView. ScaleType. CENTER_CROP); V. etImageResource (gg [I]); ShowPager. Add (v); ImageView dot=new ImageView (getContext ()); Dot. SetImageResource (R.d rawable. Dot2); Dot. SetMaxHeight (100); Dot. SetMaxWidth (100); LinearLayout. LayoutParams LayoutParams=new LinearLayout. LayoutParams (50, 50); LayoutParams. LeftMargin=20; Dot. SetLayoutParams (layoutParams); Dot. SetEnabled (false); DotViewGroup. AddView (dot); DotView. Add (dot); } viewPager. SetAdapter (new PagerAdapter () {@ Override public int getCount () {return gg. Length; } @ Override public Boolean isViewFromObject (@ NonNull View View, @ NonNull Object Object) {return View==Object; } @ NonNull @ Override public Object instantiateItem (@ NonNull ViewGroup container, int position) {ImageView ImageView=showPager. Get (position); Container. AddView (imageView); return imageView; } @ Override public void destroyItem (@ NonNull ViewGroup container, int position, @ NonNull Object Object) {container. RemoveView (Object) (View); }}); T=new Thread (this); T.s tart (); ViewPager. SetCurrentItem (0); SetDotView (0); ViewPager. AddOnPageChangeListener (new viewPager. OnPageChangeListener () {@ Override public void onPageScrolled (int position, float positionOffset, int positionOffsetPixels) {} @ Override public void onPageSelected (int position) {setDotView (position); } @ Override public void onPageScrollStateChanged (int state) {}}); }//create a View @ Nullable @ Override public View onCreateView (@ NonNull LayoutInflater inflater, @ Nullable ViewGroup container, @ Nullable Bundle savedInstanceState) {View=inflater. Inflate (R.l ayout. Fragment_one, container, false);

1

2

3

4

5

6

7

8

9

10

11.

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

Return the view;

{} @ Override public void onStart () super. OnStart (); {} @ Override public void onPause (). Super onPause (); {} @ Override public void onStop (). Super onStop (); {} @ Override public void onDestroyView () super. OnDestroyView (); {} @ Override public void onDestroy () super. OnDestroy (); {} private void setDotView (int position) for (int I=0; I & lt; DotView. The size (); I++) {dotView. Get (I). SetImageResource (position==I? R.d rawable. Dot: R.d rawable. Dot2); }} @ Override public void the run () {int item=0; While (item & lt; Gg. Length) {viewPager. SetCurrentItem (item); SetDotView (item); Try {thread.sleep (3000); } catch InterruptedException (e) {e.p rintStackTrace (); } the if (item==(gg. Length - 1)) item=0; The else item++; }}

1

2

3

4

5

6

7

8

9

10

11.

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull