簡體   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