Skip to content

Commit e33733a

Browse files
committed
feat #12: add question activity and add new data package
when start button pressed go to new question activity
1 parent 628c953 commit e33733a

File tree

6 files changed

+54
-4
lines changed

6 files changed

+54
-4
lines changed

QuizApp/app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
android:roundIcon="@mipmap/ic_launcher_round"
1010
android:supportsRtl="true"
1111
android:theme="@style/Theme.QuizApp">
12+
<activity
13+
android:name=".QuizQuestionActivity"
14+
android:screenOrientation="portrait" />
1215
<activity
1316
android:name=".MainActivity"
1417
android:screenOrientation="portrait"

QuizApp/app/src/main/java/com/example/quizapp/MainActivity.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package com.example.quizapp
22

3+
import android.content.Intent
34
import androidx.appcompat.app.AppCompatActivity
45
import android.os.Bundle
56
import android.view.View
7+
import android.widget.Button
8+
import android.widget.EditText
9+
import android.widget.Toast
610

711
@Suppress("DEPRECATION")
812
class MainActivity : AppCompatActivity() {
@@ -15,5 +19,21 @@ class MainActivity : AppCompatActivity() {
1519
// Remember that you should never show the action bar if the
1620
// status bar is hidden, so hide that too if necessary.
1721
actionBar?.hide()
22+
23+
// when start pressed go to question page
24+
val buttonStart: Button = findViewById(R.id.btn_start)
25+
buttonStart.setOnClickListener {
26+
val enterName: EditText = findViewById(R.id.et_name)
27+
if (enterName.text.toString().isEmpty()) {
28+
Toast.makeText(this, "Please enter your name", Toast.LENGTH_SHORT).show()
29+
} else {
30+
// after inter name got to quiz question page
31+
val intent = Intent(this, QuizQuestionActivity::class.java)
32+
// start new activity and finish this activity
33+
startActivity(intent)
34+
finish()
35+
}
36+
}
37+
1838
}
1939
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.example.quizapp
2+
3+
import androidx.appcompat.app.AppCompatActivity
4+
import android.os.Bundle
5+
6+
class QuizQuestionActivity : AppCompatActivity() {
7+
override fun onCreate(savedInstanceState: Bundle?) {
8+
super.onCreate(savedInstanceState)
9+
setContentView(R.layout.activity_quiz_question)
10+
}
11+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.example.quizapp.data
2+
3+
class Question {
4+
}

QuizApp/app/src/main/res/layout/activity_main.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
android:id="@+id/tv_app_name"
1414
android:layout_width="match_parent"
1515
android:layout_height="wrap_content"
16+
android:layout_marginBottom="10dp"
1617
android:gravity="center"
1718
android:text="@string/quiz_app"
1819
android:textColor="@android:color/white"
@@ -59,21 +60,23 @@
5960
android:layout_marginTop="20dp">
6061

6162
<androidx.appcompat.widget.AppCompatEditText
62-
android:layout_width="wrap_content"
63-
android:layout_height="match_parent"
63+
android:id="@+id/et_name"
64+
android:layout_width="match_parent"
65+
android:layout_height="wrap_content"
6466
android:hint="@string/hint_name"
6567
android:textColor="#363A43"
6668
android:textColorHint="#7A8089" />
6769
</com.google.android.material.textfield.TextInputLayout>
6870

6971
<Button
72+
android:id="@+id/btn_start"
7073
android:layout_width="match_parent"
7174
android:layout_height="wrap_content"
7275
android:layout_marginTop="16dp"
7376
android:background="@color/purple_700"
7477
android:text="@string/button_start"
75-
android:textSize="18sp"
76-
android:textColor="@android:color/white"/>
78+
android:textColor="@android:color/white"
79+
android:textSize="18sp" />
7780
</LinearLayout>
7881
</androidx.cardview.widget.CardView>
7982

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
tools:context=".QuizQuestionActivity">
8+
9+
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)