Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.android.quizzle;
- import java.io.BufferedReader;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.util.*;
- import java.util.zip.CheckedInputStream;
- import org.apache.http.HttpEntity;
- import org.apache.http.HttpResponse;
- import org.apache.http.NameValuePair;
- import org.apache.http.client.HttpClient;
- import org.apache.http.client.entity.UrlEncodedFormEntity;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.impl.client.DefaultHttpClient;
- import org.apache.http.message.BasicNameValuePair;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import android.app.Activity;
- import android.content.Context;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.ArrayAdapter;
- import android.widget.Button;
- import android.widget.ListView;
- import android.widget.RadioButton;
- import android.widget.RadioGroup;
- import android.widget.TextView;
- import android.widget.Toast;
- public class MainMenuActivity extends Activity implements OnClickListener{
- ListView ls1;
- String result = null;
- String result2 = null;
- InputStream is = null;
- StringBuilder sb=null;
- StringBuilder sb2=null;
- JSONArray jArray;
- String domande;
- String risposta;
- String corretta;
- RadioGroup radioGroup;
- private RadioButton radio1;
- private RadioButton radio2;
- private RadioButton radio3;
- private RadioButton radio4;
- private Button nextQuest;
- TextView t1;
- //strings2 is about questions
- ArrayList<String> strings2 = new ArrayList<String>();
- //risposte is about the related answers
- ArrayList<String> risposte = new ArrayList<String>();
- //corrette is about the right answers
- ArrayList<String> corrette = new ArrayList<String>();
- //profilo is about the results of answers
- ArrayList<Integer> profilo = new ArrayList<Integer>();
- int i = 1;
- int r = 0;
- int j = 0;
- @Override
- public void onCreate(Bundle icicle)
- {
- //here i welcome the user logger
- Bundle b = getIntent().getExtras();
- String user = b.getString("il dato inserito è: " );
- Toast.makeText(getBaseContext(), "Benvenuto: " + user ,
- Toast.LENGTH_LONG).show();
- super.onCreate(icicle);
- setContentView(R.layout.managerdb);
- ls1 = (ListView) findViewById(R.id.list);
- radioGroup = (RadioGroup)findViewById(R.id.radioGroup1);
- radio1 = (RadioButton)findViewById(R.id.radioButton1);
- radio2 = (RadioButton)findViewById(R.id.radioButton2);
- radio3 = (RadioButton)findViewById(R.id.radioButton3);
- radio4 = (RadioButton)findViewById(R.id.radioButton4);
- //here is the button
- nextQuest = (Button)findViewById(R.id.buttonNextQuest);
- t1 = (TextView)findViewById(R.id.TextView01);
- final Context context = this;
- nextQuest.setOnClickListener(this);
- View.OnClickListener btn1Listener = new View.OnClickListener() {
- @Override
- public void onClick(View v)
- {
- if(v == nextQuest)
- {
- String rispostacheck = null;
- //qui setto la domanda successiva solo se uno dei radiobutton è in un checked state.
- if(radio1.isChecked() == true)
- {
- //prendo il testo della radio chekkata.
- rispostacheck=(String) radio1.getText();
- //cerco se la risposta è contenuta nell'array JSON di risposte corrette
- if(corrette.contains(rispostacheck))
- {
- Toast.makeText(context, "Risposta esatta", Toast.LENGTH_LONG).show();
- int valoresatto = 1;
- profilo.add(valoresatto);
- Toast.makeText(context, "profilo: " + profilo, Toast.LENGTH_LONG).show();
- }
- else
- {
- Toast.makeText(context, "Risposta errata", Toast.LENGTH_LONG).show();
- int valorerrato = 0;
- profilo.add(valorerrato);
- Toast.makeText(context, "profilo: " + profilo, Toast.LENGTH_LONG).show();
- }
- //visualizzo la successiva domanda scorrendo l'arraylist di stringhe (start 1 , end 2).
- ls1.setAdapter(new ArrayAdapter<String>(context,
- android.R.layout.simple_list_item_1,
- strings2.subList(i, ++i)));
- ls1.setTextFilterEnabled(true);
- for(j=r;j<r+4;j++)
- {
- radio1.setText(risposte.get(j+1));
- radio2.setText(risposte.get(j+2));
- radio3.setText(risposte.get(j+3));
- radio4.setText(risposte.get(j+4));
- }
- }
- else if(radio2.isChecked() == true)
- {
- rispostacheck=(String) radio2.getText();
- if(corrette.contains(rispostacheck))
- {
- Toast.makeText(context, "Risposta esatta", Toast.LENGTH_LONG).show();
- int valoresatto = 1;
- profilo.add(valoresatto);
- }
- else
- {
- Toast.makeText(context, "Risposta errata", Toast.LENGTH_LONG).show();
- int valorerrato = 0;
- profilo.add(valorerrato);
- }
- ls1.setAdapter(new ArrayAdapter<String>(context,
- android.R.layout.simple_list_item_1,
- strings2.subList(i, ++i)));
- ls1.setTextFilterEnabled(true);
- for(j=r;j<r+4;j++)
- {
- radio1.setText(risposte.get(j+1));
- radio2.setText(risposte.get(j+2));
- radio3.setText(risposte.get(j+3));
- radio4.setText(risposte.get(j+4));
- }
- }
- else if(radio3.isChecked() == true)
- {
- rispostacheck=(String) radio3.getText();
- if(corrette.contains(rispostacheck))
- {
- Toast.makeText(context, "Risposta esatta", Toast.LENGTH_LONG).show();
- int valoresatto = 1;
- profilo.add(valoresatto);
- }
- else
- {
- Toast.makeText(context, "Risposta errata", Toast.LENGTH_LONG).show();
- int valorerrato = 0;
- profilo.add(valorerrato);
- }
- ls1.setAdapter(new ArrayAdapter<String>(context,
- android.R.layout.simple_list_item_1,
- strings2.subList(i, ++i)));
- ls1.setTextFilterEnabled(true);
- for(j=r;j<r+4;j++)
- {
- radio1.setText(risposte.get(j+1));
- radio2.setText(risposte.get(j+2));
- radio3.setText(risposte.get(j+3));
- radio4.setText(risposte.get(j+4));
- }
- }
- else if (radio4.isChecked() == true)
- {
- rispostacheck=(String) radio4.getText();
- if(corrette.contains(rispostacheck))
- {
- Toast.makeText(context, "Risposta esatta", Toast.LENGTH_LONG).show();
- int valoresatto = 1;
- profilo.add(valoresatto);
- }
- else
- {
- Toast.makeText(context, "Risposta errata", Toast.LENGTH_LONG).show();
- int valorerrato = 0;
- profilo.add(valorerrato);
- }
- ls1.setAdapter(new ArrayAdapter<String>(context,
- android.R.layout.simple_list_item_1,
- strings2.subList(i, ++i)));
- ls1.setTextFilterEnabled(true);
- for(j=r;j<r+4;j++)
- {
- radio1.setText(risposte.get(j+1));
- radio2.setText(risposte.get(j+2));
- radio3.setText(risposte.get(j+3));
- radio4.setText(risposte.get(j+4));
- }
- }
- else (Toast.makeText(context, "Devi selezionare una domanda", Toast.LENGTH_LONG)).show();
- }
- r+=4;
- Toast.makeText(context, "" + r, Toast.LENGTH_LONG).show();
- }
- };
- if(r <= risposte.size())
- {
- //richiamo il metodo onClick
- nextQuest.setOnClickListener(btn1Listener);
- }
- //here is other code: here i get the first question and the first 4 answers without clicking on button.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement