2017-01-02 59 views
0

所以我的主要錯誤是在ScoreDisplay.java顯示得分鑑於另一個XML

公共類ScoreDisplay擴展AppCompatActivity { INT得分;

score= getIntent().getIntExtra("score",0); 

}

INT成績是好的,但在下一行,它說 - 未知類分數 (無用)方法的聲明;返回類型需要 - 缺少方法體,或聲明抽象 - 參數預期

和高雅所以一切都是衝在我的Java類,並在那裏將我的textview.textview表演等。你告訴我了嗎?

+0

我最後的XML被稱爲scoredisplay.xml –

+0

如果你去我QuizActivity.java的底部,然後你會看到;公共無效endingScore(視圖視圖){ mfinalScoreView = mScore; –

+0

這就是我需要幫助的地方,代碼應該去那裏更新我的最終xml佈局中的值0? –

回答

0

變化

if (mQuestionNumber < mQuestionLibrary.getQuestionCount()) 
       updateQuestion(); 
       else 
        //Show next screen 
       setContentView(R.layout.scoredisplay); 

if (mQuestionNumber < mQuestionLibrary.getQuestionCount()) 
       updateQuestion(); 
else 
     { 
      Intent intent = new Intent(QuizActivity.this,ScoreDisplay.class); 
      intent.putExtra("score",mScore); 
      startActivity(intent); 
     } 

創建一個名爲ScoreDisplay新安裝插件,並接收來自QuizActivity的mScore值,通過使用該

int score; 

score= getIntent().getIntExtra("score",0); 

最後顯示的比分ScoreDisplay到你的textView

textview.setText(score+""); 

ScoreDisplay.java

public class ScoreDisplay extends AppCompatActivity { 

     TextView myScore; 
     int score; 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.scoredisplay); 
      score= getIntent().getIntExtra("score",0); 
      myScore = (TextView)findViewById(R.id.endingScore); 

      myScore.setText(score+""); 
      } 
    } 

添加下面的代碼到你的mainfest解決死機問題。

<activity android:name=".ScoreDisplay"></activity> 

AndroidMainfest FullCode

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="mgilani.co.multipleqa"> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
     <activity android:name=".QuizActivity"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    <activity android:name=".ScoreDisplay"></activity> //new line 
    </application> 

</manifest>