Advertisement
Guest User

Untitled

a guest
Jul 26th, 2011
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.86 KB | None | 0 0
  1. package com.android.quizzle;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.InputStream;
  5. import java.io.InputStreamReader;
  6. import java.util.*;
  7. import java.util.zip.CheckedInputStream;
  8.  
  9. import org.apache.http.HttpEntity;
  10. import org.apache.http.HttpResponse;
  11. import org.apache.http.NameValuePair;
  12. import org.apache.http.client.HttpClient;
  13. import org.apache.http.client.entity.UrlEncodedFormEntity;
  14. import org.apache.http.client.methods.HttpPost;
  15. import org.apache.http.impl.client.DefaultHttpClient;
  16. import org.apache.http.message.BasicNameValuePair;
  17. import org.json.JSONArray;
  18. import org.json.JSONException;
  19. import org.json.JSONObject;
  20.  
  21. import android.app.Activity;
  22. import android.content.Context;
  23.  
  24. import android.os.Bundle;
  25. import android.util.Log;
  26. import android.view.View;
  27. import android.view.View.OnClickListener;
  28. import android.widget.ArrayAdapter;
  29. import android.widget.Button;
  30. import android.widget.ListView;
  31. import android.widget.RadioButton;
  32. import android.widget.RadioGroup;
  33. import android.widget.TextView;
  34. import android.widget.Toast;
  35.  
  36. public class MainMenuActivity extends Activity implements OnClickListener{
  37.  
  38.    
  39.    
  40.     ListView ls1;
  41.    
  42.     String result = null;
  43.    
  44.     String result2 = null;
  45.    
  46.     InputStream is = null;
  47.    
  48.     StringBuilder sb=null;
  49.    
  50.     StringBuilder sb2=null;
  51.    
  52.     JSONArray jArray;
  53.    
  54.     String domande;
  55.    
  56.     String risposta;
  57.    
  58.     String corretta;
  59.    
  60.     RadioGroup radioGroup;
  61.  
  62.     private RadioButton radio1;
  63.  
  64.     private RadioButton radio2;
  65.  
  66.     private RadioButton radio3;
  67.  
  68.     private RadioButton radio4;
  69.  
  70.     private Button nextQuest;
  71.    
  72.     TextView t1;
  73.        
  74.         //strings2 is about questions
  75.     ArrayList<String> strings2 = new ArrayList<String>();
  76.         //risposte is about the related answers
  77.     ArrayList<String> risposte = new ArrayList<String>();
  78.         //corrette is about the right answers
  79.     ArrayList<String> corrette = new ArrayList<String>();
  80.         //profilo is about the results of answers
  81.     ArrayList<Integer> profilo = new ArrayList<Integer>();
  82.  
  83.     int i = 1;
  84.     int r = 0;
  85.         int j = 0;
  86.        
  87.     @Override
  88.     public void onCreate(Bundle icicle)
  89.  
  90.     {
  91.         //here i welcome the user logger
  92.         Bundle b = getIntent().getExtras();
  93.             String user = b.getString("il dato inserito è: " );
  94.             Toast.makeText(getBaseContext(), "Benvenuto: " + user ,
  95.                 Toast.LENGTH_LONG).show();
  96.        
  97.        
  98.        
  99.  
  100.                 super.onCreate(icicle);
  101.                 setContentView(R.layout.managerdb);
  102.                 ls1 = (ListView) findViewById(R.id.list);
  103.                 radioGroup = (RadioGroup)findViewById(R.id.radioGroup1);
  104.                 radio1 = (RadioButton)findViewById(R.id.radioButton1);
  105.                 radio2 = (RadioButton)findViewById(R.id.radioButton2);
  106.                 radio3 = (RadioButton)findViewById(R.id.radioButton3);
  107.                 radio4 = (RadioButton)findViewById(R.id.radioButton4);
  108.            
  109.         //here is the button
  110.              nextQuest = (Button)findViewById(R.id.buttonNextQuest);
  111.              t1 = (TextView)findViewById(R.id.TextView01);
  112.             final Context context = this;
  113.            
  114.            
  115.             nextQuest.setOnClickListener(this);
  116.            
  117.            
  118.     View.OnClickListener btn1Listener = new View.OnClickListener() {
  119.           @Override  
  120.            public void onClick(View v)
  121.            {
  122.              
  123.                 if(v == nextQuest)
  124.                 {
  125.                        
  126.                     String rispostacheck = null;   
  127.     //qui setto la domanda successiva solo se uno dei radiobutton è in un checked state.
  128.                     if(radio1.isChecked() == true)
  129.                     {
  130.                         //prendo il testo della radio chekkata.
  131.                         rispostacheck=(String) radio1.getText();
  132.                         //cerco se la risposta è contenuta nell'array JSON di risposte corrette
  133.                         if(corrette.contains(rispostacheck))
  134.                         {
  135.                             Toast.makeText(context, "Risposta esatta", Toast.LENGTH_LONG).show();
  136.                             int valoresatto = 1;
  137.                             profilo.add(valoresatto);
  138.                             Toast.makeText(context, "profilo: " + profilo, Toast.LENGTH_LONG).show();
  139.  
  140.                         }
  141.                         else
  142.                         {
  143.                             Toast.makeText(context, "Risposta errata", Toast.LENGTH_LONG).show();
  144.                             int valorerrato = 0;
  145.                             profilo.add(valorerrato);
  146.                             Toast.makeText(context, "profilo: " + profilo, Toast.LENGTH_LONG).show();
  147.                         }
  148.                         //visualizzo la successiva domanda scorrendo l'arraylist di stringhe (start 1 , end 2).
  149.                         ls1.setAdapter(new ArrayAdapter<String>(context,
  150.                         android.R.layout.simple_list_item_1,
  151.                         strings2.subList(i, ++i)));
  152.                         ls1.setTextFilterEnabled(true);
  153.                         for(j=r;j<r+4;j++)
  154.                         {
  155.                                 radio1.setText(risposte.get(j+1));
  156.                                 radio2.setText(risposte.get(j+2));
  157.                                 radio3.setText(risposte.get(j+3));
  158.                                 radio4.setText(risposte.get(j+4));
  159.                                
  160.                         }  
  161.                     }
  162.                     else if(radio2.isChecked() == true)
  163.                     {
  164.                         rispostacheck=(String) radio2.getText();
  165.                         if(corrette.contains(rispostacheck))
  166.                         {
  167.                             Toast.makeText(context, "Risposta esatta", Toast.LENGTH_LONG).show();
  168.                             int valoresatto = 1;
  169.                             profilo.add(valoresatto);
  170.                            
  171.  
  172.                         }
  173.                         else
  174.                         {
  175.                             Toast.makeText(context, "Risposta errata", Toast.LENGTH_LONG).show();
  176.                             int valorerrato = 0;
  177.                             profilo.add(valorerrato);
  178.                            
  179.  
  180.                         }
  181.                         ls1.setAdapter(new ArrayAdapter<String>(context,
  182.                                 android.R.layout.simple_list_item_1,
  183.                                 strings2.subList(i, ++i)));
  184.                                 ls1.setTextFilterEnabled(true);
  185.                        
  186.                         for(j=r;j<r+4;j++)
  187.                                 {
  188.                                         radio1.setText(risposte.get(j+1));
  189.                                         radio2.setText(risposte.get(j+2));
  190.                                         radio3.setText(risposte.get(j+3));
  191.                                         radio4.setText(risposte.get(j+4));
  192.                                        
  193.                                 }  
  194.                        
  195.                     }
  196.                     else if(radio3.isChecked() == true)
  197.                     {
  198.                         rispostacheck=(String) radio3.getText();
  199.                         if(corrette.contains(rispostacheck))
  200.                         {
  201.                             Toast.makeText(context, "Risposta esatta", Toast.LENGTH_LONG).show();
  202.                             int valoresatto = 1;
  203.                             profilo.add(valoresatto);
  204.                            
  205.  
  206.                         }
  207.                         else
  208.                         {
  209.                             Toast.makeText(context, "Risposta errata", Toast.LENGTH_LONG).show();
  210.                             int valorerrato = 0;
  211.                             profilo.add(valorerrato);
  212.                            
  213.  
  214.                         }
  215.                         ls1.setAdapter(new ArrayAdapter<String>(context,
  216.                                 android.R.layout.simple_list_item_1,
  217.                                 strings2.subList(i, ++i)));
  218.                                 ls1.setTextFilterEnabled(true);
  219.                         for(j=r;j<r+4;j++)
  220.                                 {
  221.                                         radio1.setText(risposte.get(j+1));
  222.                                         radio2.setText(risposte.get(j+2));
  223.                                         radio3.setText(risposte.get(j+3));
  224.                                         radio4.setText(risposte.get(j+4));
  225.                                        
  226.                                 }  
  227.                     }
  228.                     else if (radio4.isChecked() == true)
  229.                     {  
  230.                         rispostacheck=(String) radio4.getText();
  231.                         if(corrette.contains(rispostacheck))
  232.                         {
  233.                             Toast.makeText(context, "Risposta esatta", Toast.LENGTH_LONG).show();
  234.                             int valoresatto = 1;
  235.                             profilo.add(valoresatto);
  236.                            
  237.  
  238.                         }
  239.                         else
  240.                         {
  241.                             Toast.makeText(context, "Risposta errata", Toast.LENGTH_LONG).show();
  242.                             int valorerrato = 0;
  243.                             profilo.add(valorerrato);
  244.                            
  245.  
  246.                         }
  247.    
  248.                             ls1.setAdapter(new ArrayAdapter<String>(context,
  249.                             android.R.layout.simple_list_item_1,
  250.                             strings2.subList(i, ++i)));
  251.                             ls1.setTextFilterEnabled(true);
  252.                     for(j=r;j<r+4;j++)
  253.                             {
  254.                                     radio1.setText(risposte.get(j+1));
  255.                                     radio2.setText(risposte.get(j+2));
  256.                                     radio3.setText(risposte.get(j+3));
  257.                                     radio4.setText(risposte.get(j+4));
  258.                                    
  259.                             }      
  260.                          
  261.                     }
  262.                    
  263.                     else (Toast.makeText(context, "Devi selezionare una domanda", Toast.LENGTH_LONG)).show();
  264.                    
  265.                  }
  266.                 r+=4;
  267.                 Toast.makeText(context, "" + r, Toast.LENGTH_LONG).show();
  268.  
  269.              }
  270.            
  271.          };
  272.          if(r <= risposte.size())
  273.             {
  274.          //richiamo il metodo onClick
  275.              nextQuest.setOnClickListener(btn1Listener);
  276.            }
  277.          
  278.                
  279.            //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