Like Us on Facebook

How to make a Simple Quiz App in Android

Hello everyone ,  Quiz Application has become popular for many  Internet user  and also for   for the smartphone user .Answering quiz can be a fun way to exercise your brain cells, as well as kill those idle moments when you’re at the office or waiting for the bus From Online quiz contest  many user can win cash , rewards and more prizes . in this post I am going to share you to make a simple quiz application in Android.


Prerequisites:
 
  • JDK 7.0 or above
  • Android Studio


Steps to follow:  
 
  1. Create a New Android Studio project name  QuizApp.
  2. Select minimum  API level 16 so it will run maximum Android device that are Active on google Play then click next.
  3. Select Blank Activity and your Activity name is MainActivity click next > click finish.
  4. Now inside MainActivity.java  write the following code
 
public class MainActivity extends AppCompatActivity {
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button)findViewById(R.id.button);

btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

Intent i = new Intent("com.tutorial.quizapp.FIRSTQUIZ");
startActivity(i);
 }
 });
 }

@Override
 public boolean onCreateOptionsMenu(Menu menu) {
 // Inflate the menu; this adds items to the action bar if it is present.
 
getMenuInflater().inflate(R.menu.menu_main, menu);
 return true;
 }

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.

int id = item.getItemId();
//noinspection SimplifiableIfStatement
 
if (id == R.id.action_settings) {
 return true;
 }
return super.onOptionsItemSelected(item);
 }
}

 



5.Now create a new class  FirstQuiz.java . inside it write the following code
 
public class FirstQuiz extends AppCompatActivity {
private RadioGroup radioGroup;
private Button nxt;
int pos;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.quiz1);
radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

@Override
public void onCheckedChanged(RadioGroup group, int checkedId){
if (checkedId == R.id.radio1) {
setContentView(R.layout.final2);
}
else if (checkedId == R.id.radio2){
setContentView(R.layout.final2);
}
else if (checkedId == R.id.radio3) {
setContentView(R.layout.final1);
}
else{
setContentView(R.layout.final2);
}
}
});
}
}



 6. And the required xml file are like below.

activity_main.xml
 
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Welcome to Quiz"
android:textColor="#0000ff"
android:textSize="40sp"
android:id="@+id/textView2"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="160dp"/>

 <Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="proceed >"
android:textColor="#ffffff"
android:background="#0000ff"
android:textSize="25dp"
android:id="@+id/button"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"/>

</RelativeLayout>  


  
quiz1.xml

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 
android:layout_width="match_parent"
 
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="which bowler has more than 500 wicket in One day international?"
android:textSize="20sp"
android:id="@+id/textView4"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"/>

<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/textView4"
android:layout_marginTop="116dp"
android:layout_above="@+id/button2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="@+id/radioGroup">

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Shaun pollock"
android:id="@+id/radio1"
android:layout_gravity="center_horizontal"/>

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chaminda vaas"
android:id="@+id/radio2"
android:layout_alignTop="@+id/radioGroup"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"/>

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Wasim Akram"
android:id="@+id/radio3"
android:layout_gravity="center_horizontal"/>

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Zaheer Khan"
android:id="@+id/radio4"
android:layout_gravity="center_horizontal"/>
</RadioGroup>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="next >"
android:id="@+id/button2"
android:layout_marginBottom="54dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>

</RelativeLayout>
 


final1.xml
 
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=" yes!! write answer"
android:textColor="#00ff00"
android:textSize="25sp"
android:id="@+id/textView5"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>

</RelativeLayout>



final2.xml
 
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Sorry, wrong Answer"
android:textColor="#ff0000"
android:textSize="25sp"
android:id="@+id/textView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>

</RelativeLayout>

Posted By UandBlog

UandBlog is a Global Leading source of Finance, Health, Lifestyle, Technology, Gaming and Programing and other information, it is a fastest growing blog for all , for latest post or information like us on facebook , follow on Twitter, Google+ and Pinterest.

Comments ( 1 )

sanne nebeabi:
Thanks a lot

    Leave a comment..

    Click to login.

    Subscribe Latest Information

    Most Popular Posts

    You May Like Also