變化
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>
我最後的XML被稱爲scoredisplay.xml –
如果你去我QuizActivity.java的底部,然後你會看到;公共無效endingScore(視圖視圖){ mfinalScoreView = mScore; –
這就是我需要幫助的地方,代碼應該去那裏更新我的最終xml佈局中的值0? –