Skip to content

Instantly share code, notes, and snippets.

@coldyca coldyca/activity_main.xml
Last active Apr 11, 2017

Embed
What would you like to do?
c++ quiz app
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background25">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.android.cquiz.MainActivity">
<ImageView
android:id="@+id/name"
android:layout_gravity="center"
android:layout_width="@dimen/dimentionImage"
android:layout_height="@dimen/dimentionImage"
android:background="@drawable/c"/>
<TextView
android:layout_width="wrap_content"
android:textColor="@color/textColor"
android:paddingTop="@dimen/spaceBetween"
android:textSize="@dimen/textSizeTitle"
android:fontFamily="@string/textFont"
android:layout_gravity="center"
android:text="@string/title"
android:layout_height="wrap_content" />
<TextView
android:paddingTop="@dimen/spaceBetween"
android:paddingLeft="@dimen/spaceBetween"
android:layout_width="wrap_content"
android:textColor="@color/textColor"
android:fontFamily="@string/textFont"
android:textSize="@dimen/textSizeNormal"
android:text="@string/nameText"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/insertName"
android:inputType="textCapWords"
android:hint="@string/hint"
android:textColorHint="@color/textColor"
android:textColor="@color/textColor"
android:fontFamily="@string/textFont"
android:paddingLeft="@dimen/spaceBetween"
android:textSize="@dimen/textSizeNormal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:paddingTop="@dimen/spaceBetweenDouble"
android:paddingLeft="@dimen/spaceBetween"
android:layout_width="wrap_content"
android:textColor="@color/textColor"
android:fontFamily="@string/textFont"
android:textSize="@dimen/textSizeNormal"
android:text="@string/rulesTest"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="@string/start"
android:onClick="startTest" />
</LinearLayout>
</ScrollView>
2 images with backgourn and c++ icon
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="textColor">#ffffff</color>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="dimentionImage">150dp</dimen>
<dimen name="textSizeTitle">22sp</dimen>
<dimen name="textSizeNormal">16sp</dimen>
<dimen name="spaceBetweenSmall">5dp</dimen>
<dimen name="spaceBetweenMedium">15dp</dimen>
<dimen name="spaceBetween">20dp</dimen>
<dimen name="spaceBetweenDouble">40dp</dimen>
<dimen name="spaceBetween3Times">60dp</dimen>
<dimen name="spaceBetween7Times">140dp</dimen>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="textFont">casual</string>
<string name="center">center</string>
</resources>
package com.example.android.cquiz;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;
import org.w3c.dom.Text;
import static android.R.attr.button;
import static android.R.attr.checked;
import static android.R.attr.keyTextSize;
import static android.R.attr.verticalCorrection;
import static android.R.id.message;
import static android.icu.lang.UCharacter.GraphemeClusterBreak.T;
import static com.example.android.cquiz.R.id.checkbox4;
import static com.example.android.cquiz.R.id.radio;
import static com.example.android.cquiz.R.id.radioButton1;
import static com.example.android.cquiz.R.id.radioGroup1;
import static com.example.android.cquiz.R.id.textView;
public class MainActivity extends AppCompatActivity {
String name="";
int score=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
protected void startTest(View view)
{
name=((EditText) findViewById(R.id.insertName)).getText().toString();
if (name.length()==0) {
Message("Please imput your name");
setContentView(R.layout.activity_main);
}
else {
setContentView(R.layout.question1);
}
}
protected void page2(View view)
{
if( ((RadioButton) findViewById(R.id.radioButton1)).isChecked())
{
score += 2;
Message("Correct");
}
else Message("Wrong");
setContentView(R.layout.question2);
}
protected void page3(View view)
{
String answerString =((EditText) findViewById(R.id.answer)).getText().toString();
if (answerString.length()==0) {
Message("Plese type a value");
setContentView(R.layout.question2);
}
else
{
if( Integer.valueOf(answerString)== Integer.valueOf(getResources().getString(R.string.question2Corect))) {
score += 2;
Message("Correct");
}
else Message("Wrong");
setContentView(R.layout.question3);
}
}
protected void page4(View view)
{
int corect=0;
if( ((CheckBox) findViewById(R.id.checkbox1)).isChecked() )
{
score += 1;
corect=1;
}
if( ((CheckBox) findViewById(R.id.checkbox3)).isChecked() )
{
score += 1;
corect+=1;
}
if (corect==1)
Message("Half is correct");
else if(corect==2)
Message("Correct");
else Message("Wrong");
setContentView(R.layout.question4);
}
protected void page5(View view)
{
if(((RadioButton) findViewById(R.id.checkbox2)).isChecked()) {
score += 2;
Message("Correct");
}
else Message("Wrong");
setContentView(R.layout.question5);
}
protected void score(View view)
{
String answerString =((EditText) findViewById(R.id.answerQuestion)).getText().toString();
if (answerString.length()==0) {
Message("Plese type a value");
setContentView(R.layout.question5);
}
else
{
if( answerString.toUpperCase()== (getResources().getString(R.string.question5Corect)).toUpperCase()) {
score += 2;
Message("Correct");
}
else Message("Wrong");
setContentView(R.layout.score);
((TextView) findViewById(R.id.scoreView)).setText(getString(R.string.score,name,String.valueOf(score)));
}
}
protected void restart(View view)
{
String name="";
score=0;
setContentView(R.layout.activity_main);
}
protected void Message(String value)
{
Context context = getApplicationContext();
CharSequence text = String.valueOf(value);
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background25">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.android.cquiz.question3">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@string/textFont"
android:paddingBottom="@dimen/spaceBetween"
android:paddingLeft="@dimen/spaceBetween"
android:paddingTop="@dimen/spaceBetween"
android:text="@string/question3"
android:textColor="@color/textColor"
android:textSize="@dimen/textSizeTitle" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/spaceBetween">
<CheckBox
android:id="@+id/checkbox1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="@color/textColor"
android:buttonTint="@color/textColor"
android:textSize="@dimen/textSizeTitle"
android:fontFamily="@string/textFont"
android:padding="@dimen/spaceBetweenMedium"
android:text="@string/optionA"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<CheckBox
android:id="@+id/checkbox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/textColor"
android:buttonTint="@color/textColor"
android:padding="@dimen/spaceBetweenMedium"
android:textSize="@dimen/textSizeTitle"
android:fontFamily="@string/textFont"
android:layout_toRightOf="@+id/checkbox1"
android:text="@string/optionB" />
<CheckBox
android:id="@+id/checkbox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/textColor"
android:buttonTint="@color/textColor"
android:textSize="@dimen/textSizeTitle"
android:fontFamily="@string/textFont"
android:layout_toRightOf="@+id/checkbox2"
android:padding="@dimen/spaceBetweenMedium"
android:text="@string/optionC" />
<CheckBox
android:id="@+id/checkbox4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="@color/textColor"
android:buttonTint="@color/textColor"
android:textSize="@dimen/textSizeTitle"
android:fontFamily="@string/textFont"
android:layout_toRightOf="@+id/checkbox3"
android:padding="@dimen/spaceBetweenMedium"
android:text="@string/optionD" />
<Button
android:layout_width="@dimen/spaceBetween7Times"
android:layout_height="wrap_content"
android:layout_below="@+id/checkbox1"
android:text="@string/next"
android:layout_alignParentRight="true"
android:onClick="page4"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background25">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.android.cquiz.question5">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@string/textFont"
android:paddingBottom="@dimen/spaceBetween"
android:paddingLeft="@dimen/spaceBetween"
android:paddingTop="@dimen/spaceBetween"
android:text="@string/question5"
android:textColor="@color/textColor"
android:textSize="@dimen/textSizeTitle" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/spaceBetween">
<EditText
android:id="@+id/answerQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/textColor"
android:fontFamily="@string/textFont"
android:hint="@string/answerText"
android:padding="@dimen/spaceBetweenSmall"
android:textSize="@dimen/textSizeNormal" />
<Button
android:layout_width="@dimen/spaceBetween7Times"
android:layout_height="wrap_content"
android:layout_below="@+id/answerQuestion"
android:text="@string/next"
android:onClick="score"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background25">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.android.cquiz.question1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/textColor"
android:fontFamily="@string/textFont"
android:textSize="@dimen/textSizeTitle"
android:paddingTop="@dimen/spaceBetween"
android:paddingLeft="@dimen/spaceBetween"
android:text="@string/question1"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/spaceBetween"
android:buttonTint="@color/textColor"
android:checked="false"
android:fontFamily="@string/textFont"
android:gravity="bottom"
android:paddingLeft="@dimen/spaceBetween"
android:paddingTop="@dimen/spaceBetween"
android:text="@string/question1Answer1"
android:textColor="@color/textColor"
android:textSize="@dimen/textSizeTitle" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/spaceBetween"
android:buttonTint="@color/textColor"
android:checked="false"
android:fontFamily="@string/textFont"
android:gravity="bottom"
android:paddingLeft="@dimen/spaceBetween"
android:paddingTop="@dimen/spaceBetween"
android:text="@string/question1Answer2"
android:textColor="@color/textColor"
android:textSize="@dimen/textSizeTitle" />
<RadioButton
android:id="@+id/radioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/spaceBetween"
android:buttonTint="@color/textColor"
android:checked="false"
android:fontFamily="@string/textFont"
android:gravity="bottom"
android:paddingLeft="@dimen/spaceBetween"
android:paddingTop="@dimen/spaceBetween"
android:text="@string/question1Answer3"
android:textColor="@color/textColor"
android:textSize="@dimen/textSizeTitle" />
<RadioButton
android:id="@+id/radioButton4"
android:checked="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@color/textColor"
android:fontFamily="@string/textFont"
android:layout_marginLeft="@dimen/spaceBetween"
android:gravity="bottom"
android:paddingLeft="@dimen/spaceBetween"
android:paddingTop="@dimen/spaceBetween"
android:text="@string/question1Answer4"
android:textColor="@color/textColor"
android:textSize="@dimen/textSizeTitle"
android:layout_alignBaseline="@+id/radioButton3"
android:layout_toRightOf="@+id/radioButton3" />
</RadioGroup>
<Button
android:layout_toRightOf="@+id/radioGroup1"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_width="@dimen/spaceBetween"
android:layout_height="wrap_content"
android:text="@string/next"
android:onClick="page2"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background25">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.android.cquiz.question2">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@string/textFont"
android:paddingBottom="@dimen/spaceBetween"
android:paddingLeft="@dimen/spaceBetween"
android:paddingTop="@dimen/spaceBetween"
android:text="@string/question2"
android:textColor="@color/textColor"
android:textSize="@dimen/textSizeTitle" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/spaceBetween">
<EditText
android:id="@+id/answer"
android:layout_width="@dimen/spaceBetween7Times"
android:layout_height="wrap_content"
android:background="@color/textColor"
android:digits="0123456789"
android:inputType="number"
android:fontFamily="@string/textFont"
android:hint="@string/answer"
android:padding="@dimen/spaceBetweenSmall"
android:textSize="@dimen/textSizeNormal" />
<Button
android:layout_width="@dimen/spaceBetween7Times"
android:layout_height="wrap_content"
android:layout_below="@+id/answer"
android:text="@string/next"
android:onClick="page3"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background25">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.android.cquiz.question4">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/textColor"
android:fontFamily="@string/textFont"
android:textSize="@dimen/textSizeTitle"
android:paddingTop="@dimen/spaceBetween"
android:paddingLeft="@dimen/spaceBetween"
android:text="@string/question4"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/spaceBetween">
<RadioGroup
android:id="@+id/radioGroupPage4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<RadioButton
android:id="@+id/checkbox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/textColor"
android:buttonTint="@color/textColor"
android:textSize="@dimen/textSizeTitle"
android:fontFamily="@string/textFont"
android:padding="@dimen/spaceBetweenMedium"
android:text="@string/question4Answer1"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<RadioButton
android:id="@+id/checkbox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@color/textColor"
android:fontFamily="@string/textFont"
android:padding="@dimen/spaceBetweenMedium"
android:text="@string/question4Answer2"
android:textColor="@color/textColor"
android:textSize="@dimen/textSizeTitle" />
<RadioButton
android:id="@+id/checkbox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/textColor"
android:buttonTint="@color/textColor"
android:textSize="@dimen/textSizeTitle"
android:fontFamily="@string/textFont"
android:padding="@dimen/spaceBetweenMedium"
android:text="@string/question4Answer3" />
</RadioGroup>
<Button
android:layout_width="@dimen/spaceBetween7Times"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/radioGroupPage4"
android:text="@string/next"
android:layout_alignParentRight="true"
android:onClick="page5"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background25">
<LinearLayout
android:layout_marginTop="@dimen/spaceBetween3Times"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.android.cquiz.score">
<TextView
android:id="@+id/scoreView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@string/textFont"
android:paddingBottom="@dimen/spaceBetween"
android:paddingLeft="@dimen/spaceBetween"
android:paddingTop="@dimen/spaceBetween"
android:textColor="@color/textColor"
android:textSize="@dimen/textSizeTitle" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:onClick="restart"
android:text="@string/restart" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">C++ quiz</string>
<string name="title">Welcome to beginner c++ test!</string>
<string name="nameText">Please insert your name:</string>
<string name="hint">Name</string>
<string name="optionA">a)</string>
<string name="optionB">b)</string>
<string name="optionC">c)</string>
<string name="optionD">d)</string>
<string name="answer">Numbers only</string>
<string name="answerText">Write the text here</string>
<string name="start">Start the test</string>
<string name="rulesTest">Try to answer as many questions you can.\nKeep in mind that some answer have more than one correct answer.\nGood luck!!!</string>
<string name="question1">1st question:\n\nThe printed message on the screen will be: \n\nint a = 4;\ncout &lt;&lt; a ++;</string>
<string name="question2">2nd question:\n\nWrite the number that will be printed on the screen will be: \n\nint a = 4;\nint b = 8;\ncout &lt;&lt; (a+(++b));</string>
<string name="question3">3nd question:\n\nSelect the options that you think are correct: \n\na) string a = \"4\";\nb) string b = Happy;\nc) string c = \"+\'!\&lt;&lt;\"\nd) string d = 99;</string>
<string name="question4">4th question:\n\nThe corect option is:\nint a =6, b=6;\nif (a++ > ++b) \ncout&lt;&lt; \"A este mai mare\";\nelse if (a++ &lt; ++b)\n cout&lt;&lt; \"B este mai mare\";\nelse &lt;&lt; \"A este egal cu B\";</string>
<string name="question5">5th question:\n\nWrite the string that will be printed on the screen will be: \n\n
string a =\"I would like to\",\n
b = a.Substring(1, 1) + \"go\" + a.Substring(12, 3) + a.Substring(1, 1),\n
c = \" the next round!\";\n
cout &lt;&lt; a + b + c;</string>
<string name="score">Congratulation %1$s you did it!\n\nYou finish all the question with a surprising result of %2$s out of 10.\n\nIf you want to play again just press the button RESTART.</string>
<string name="next">Next question</string>
<string name="question1Answer1">4;</string>
<string name="question1Answer2">3;</string>
<string name="question1Answer3">5;</string>
<string name="question4Answer1">A este mai mare</string>
<string name="question4Answer2">B este mai mare</string>
<string name="question4Answer3">A este egal cu B</string>
<string name="question1Answer4">Error message;</string>
<string name="question1Corect">4</string>
<string name="question2Corect">13</string>
<string name="question3Corect">a)b)c)</string>
<string name="question4Corect">c)</string>
<string name="restart">Restart</string>
<string name="question5Corect">I would like to go to the next round!</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#03A9F4</item>
<item name="colorPrimaryDark">#0288D1</item>
<item name="colorAccent">#ff4082</item>
</style>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.