Rajubhai Rathod Rajubhai Rathod - 4 months ago 10
Android Question

newInstance in class

I am trying to implement android introduction library in one of my application located here. I have followed instruction as given in library page. When I try to use R. for text and image reference, when I add more than 3 R. reference I am getting error like

The method newInstance(CharSequence, CharSequence, int, int) in the type AppIntroFragment is not applicable for the arguments (int, int, int, int)


My Class is like below

public void init(@Nullable Bundle bundle) {

addSlide(AppIntroFragment.newInstance(R.string.title_1, R.string.description_1, R.drawable.rateme, R.color.colorPrimaryDark));
addSlide(AppIntroFragment.newInstance("hi", "hello", R.drawable.rateme, R.color.colorPrimaryDark));
addSlide(AppIntroFragment.newInstance("hi", "hello", R.drawable.rateme, R.color.colorPrimaryDark));
setBarColor(Color.parseColor("#3F51B5"));
setSeparatorColor(Color.parseColor("#2196F3"));

// Hide Skip/Done button.
showSkipButton(true);
setProgressButtonEnabled(true);

// Turn vibration on and set intensity.
// NOTE: you will probably need to ask VIBRATE permisssion in Manifest.
setVibrate(true);
setVibrateIntensity(30);
}

private void loadMainActivity(){
Intent intent = new Intent(this, HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
}

@Override
public void onSkipPressed(Fragment currentFragment) {
super.onSkipPressed(currentFragment);
loadMainActivity();
}
@Override
public void onDonePressed(Fragment currentFragment) {
super.onDonePressed(currentFragment);
loadMainActivity();
}

public void getStarted(View v){
loadMainActivity();
}


What should I do for solve the issue ?

Thanks

Answer

Change this

addSlide(AppIntroFragment.newInstance(R.string.title_1, R.string.description_1, R.drawable.rateme, R.color.colorPrimaryDark));

to this

addSlide(AppIntroFragment.newInstance(getString(R.string.title_1), getString(R.string.description_1), R.drawable.rateme, R.color.colorPrimaryDark));

The constructor expects a CharSequence but you are passing a int.

Comments