繁体   English   中英

类中的newInstance

[英]newInstance in class

我试图在我位于此处的一个应用程序中实现android Introduction库。 我已按照图书馆页面中的指示进行操作。 当我尝试使用R.作为文本和图像参考时,当我添加3个以上R. reference时,出现了类似的错误

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

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

谢谢

改变这个

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值。

替换您的下一行

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM