newInstance在课堂上

时间:2016-07-06 04:34:05

标签: java android

我正在尝试在位于here的应用程序中实现android简介库。我已按照图书馆页面中的说明进行操作。当我尝试使用R.进行文本和图像引用时,当我添加超过3个R.参考时,我会收到类似

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

我的班级如下

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();
}

我该怎么做才能解决问题?

由于

2 个答案:

答案 0 :(得分:1)

更改此

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

到这个

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

构造函数需要CharSequence,但是您传递的是int。

答案 1 :(得分:0)

替换您的以下

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

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