在另一个XML中显示分数视图

时间:2017-01-02 14:18:02

标签: java android xml

所以我的主要错误在ScoreDisplay.java

public class ScoreDisplay扩展AppCompatActivity {     int score;

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

}

int得分很好,但在下一行中它说 - 未知的班级成绩 - 无效的方法声明;需要返回类型 - 缺少方法体,或声明抽象 - 参数预期

并且所以我的java类中的所有内容都是红色的,我在哪里放置textview.textview show等。你告诉我了吗?

1 个答案:

答案 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的新jave,并使用此

从QuizActivity接收mScore值到ScoreDisplay
int score;

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

最后将分数显示在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+"");
           }
    }

将以下代码添加到您的主要节目以解决崩溃问题。

<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>
相关问题