I am new to the group, I have a problem with making a slider functional (intro) on the cell phone. everything comes out ok when I give it Run, but when I install the application to verify, a warning comes out "unfortunately, test1 has stopped". Thank you very much
I attached the sync
here is the gradle, I do not know if it will be the problem for the sdk.
It's the code of the intro. If any information you want, I can provide it. Thanks
private ViewPager viewPager;
private LinearLayout layoutDot;
private TextView[]dotstv;
private int [] layouts;
private Button btnSkip;
private Button btnNext;
private MyPagerAdapter pagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//aqui conecta con el xml
setContentView(R.layout.activity_main);
viewPager= findViewById(R.id.view_pager);
layoutDot=findViewById(R.id.dotLayout);
btnNext=findViewById(R.id.btn_next);
btnSkip=findViewById(R.id.btn_skip);
//when user press skip, start main activity
btnSkip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startMainActivity ();
}
});
btnSkip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int currentPage = viewPager.getCurrentItem()+1;
if (currentPage < layouts.length){
//move to next page
viewPager.setCurrentItem(currentPage);
}else {
startMainActivity();
}
}
});
layouts = new int[] {R.layout.slide_1, R.layout.slide_2, R.layout.slide_3, R.layout.slide_4};
pagerAdapter = new MyPagerAdapter(layouts,getApplicationContext());
viewPager.setAdapter(pagerAdapter);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int i, float v, int i1) {
}
@Override
public void onPageSelected(int position) {
if (position == layouts.length - 1) {
btnNext.setText("START");
btnSkip.setVisibility(View.GONE);
}else {
btnNext.setText("NEXT");
btnSkip.setVisibility(View.VISIBLE);
}
setDotStatus(position);
}
@Override
public void onPageScrollStateChanged(int i) {
}
});
setDotStatus(0);
}
private boolean isFirstTimeStartApp (){
SharedPreferences ref = getApplicationContext().getSharedPreferences("IntroSlider", Context.MODE_PRIVATE );
return ref.getBoolean( "FirstTimeStartFlag",true );
}
private void setFirstTimeStatus (boolean stt) {
SharedPreferences ref = getApplicationContext().getSharedPreferences("IntroSlider", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = ref.edit();
editor.putBoolean("FirstTimeStarting", stt);
editor.commit();
}
private void setDotStatus (int page){
layoutDot.removeAllViews();
dotstv=new TextView[layouts.length];
for (int i = 0; i < dotstv.length; i++){
dotstv[i] = new TextView(this);
dotstv[i].setText(Html.fromHtml("•"));
dotstv[i].setTextSize(30);
dotstv[i].setTextColor(Color.parseColor("#a9b4bb"));
layoutDot.addView(dotstv[i]);
}
//set current to Dot
if (dotstv.length > 0){
dotstv[page].setTextColor(Color.parseColor("#ffffff"));
}
}
private void startMainActivity () {
//true when mainactivity start
setFirstTimeStatus (false);
startActivity(new Intent(WelcomeActivity.this, MainActivity.class));
finish();
}
private void SetStatusBarTransparent () {
if(Build.VERSION.SDK_INT >=21){
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE|View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
}
}
}