ViewPager
2020. 3. 29. 20:52ㆍAndroid
반응형
public class GuideViewPager extends PagerAdapter {
private static final String TAG = GuideViewPager.class.getSimpleName();
private static final int PAGE_COUNT = 3;
private Context mContext;
public GuideViewPager(Context context){
mContext = context;
}
@Override
public int getCount() {
return PAGE_COUNT;
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object obj) {
return view == obj;
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = null;
switch (position){
case 0 :
view = inflater.inflate(R.layout.view_guide_0, null);
container.addView(view, position);
return view;
case 1 :
view = inflater.inflate(R.layout.view_guide_1, null);
container.addView(view, position);
return view;
case 2 :
view = inflater.inflate(R.layout.view_guide_2, null);
container.addView(view, position);
return view;
}
return null;
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
View view = (View) object;
container.removeView(view);
}
@Override
public int getItemPosition(@NonNull Object object) {
return super.getItemPosition(object);
}
}
public class GuideActivity extends BaseActivity {
private static final String TAG =GuideActivity.class.getSimpleName();
private Unbinder mUnbinder;
@BindView(R.id.viewpager_guide)
public ViewPager mViewPager;
@BindView(R.id.btn_start)
public Button mBtnStart;
private Bundle mBundle = null;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_guide);
mUnbinder = ButterKnife.bind(this);
GuideViewPager guideViewPager = new GuideViewPager(this);
mViewPager.setAdapter(guideViewPager);
}
@Override
public void callRequestServer(String params) {
}
@OnClick(R.id.btn_start)
void onButtonOkClick(){
PreferenceUtil.getInstance(mBaseActivity).setBoolean(Constant.PreferenceKeys.GUIDE, true);
Intent i = new Intent(this, MainActivity.class);
startActivity(i);
finish();
}
@Override
protected void onDestroy() {
super.onDestroy();
if(mUnbinder != null) mUnbinder.unbind();
}
}
반응형
'Android' 카테고리의 다른 글
안드로이드 RecyclerView 성능 개선팁 (0) | 2020.12.10 |
---|---|
HorizontalScrollView Scroll Animation (0) | 2020.12.10 |
Install Referrer API (0) | 2020.03.17 |
Android Jetpack & KTX (0) | 2020.03.05 |
AAC(Android Architecture Components) (0) | 2019.09.13 |