2017-01-02 108 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>