views:

57

answers:

1

Possible Duplicate:
how to check whether an element already exists in the array

I am developing an app for blackberry, its like a test paper, each time a user clicks start button, 10 questions are being displayed from an xml database which contains 20 questions, then the result is shown in percentage.

Now what i want to do is to store each question which is being dispalyed into blackberry persitentobject, so that when one test is over and the user exit the application, then again when he starts the app,the 10 questions which has already been displayed at earlier test should not be displayed this time.

I have used persistentobject for other requirements, but in this case i am facing some problem comparing from memory, whether the value which i am sending is already present in the memory. So if anyone can kindly help me with the coding, it would be very helpful for me.

I am giving the pages... Plz help me with what should be the logic to compare whether the data i am sending frm DBMain page to TestScreen page is already present or not, if it already exist in memory, then dont send that value.

DBMain Page

 public static int getQuestionNumber() {


  //int quesCount;
     //quesCount++;
  //synchronized (curQues) {
   //quesCount = Integer.parseInt((String)curQues.getContents());
  //}
   quesCount++;
     synchronized (curans) {

    int b=Integer.parseInt(TopManager.corrCount);
    curans.setContents(b+"");
    curans.commit();

   }
 //int quesNum[];

  synchronized (qStore) {
   quesNum=(int[]) qStore.getContents();
   System.out.println("The value of question is ...."+quesNum.length);
 }


  synchronized (pQues) {

   int a=Integer.parseInt(TopManager.quesNumber);
   pQues.setContents(a+"");
   pQues.commit();

  }


  if (quesNum!=null && quesCount < quesNum.length) {

   synchronized (curQues) {

    curQuesnew=quesNum[quesCount];
    curQues.setContents(curQuesnew+"");
    curQues.commit(); 
   }
   for (int i=0; i< c.length; i++) {

       c[i]=TestScreen.quesNumbernew[i];

   }
   //i have used this logic to save the data which i am sending to the other page//   synchronized (disques) {
     Vector data = new Vector();
    data.addElement(quesNum[quesCount]+"");
        disques.setContents(data);
        disques.commit();
        }
    synchronized (disques) {
     data = (Vector)disques.getContents();
    }

       if (data.contains(quesNum)){ //i hav used this logic to compare the data i am sending,& the data that is already present,bt its nt working//

       xyz=quesNum[quesCount];


              }

              return xyz;//this is the data which i am actually sending//


 } else {
   initialize();
   quesCount = -1;
   return getQuestionNumber();
  }

 }

TestScreen page //this is the page to which we are sending the data//

  String title = "";

   quesNumber = DBMain.getQuestionNumber();//this is where the value is coming//
   System.out.println("the value of QUESNUMBERNEW:"+quesNumbernew[i]);
  //quesNumber.addElement(DBMain.getQuestionNumber()+"");
  //int a=quesNumber.elementAt(quesNumber);
  System.out.println("the value of QUESNUMBER:"+quesNumber);
  DBMain.curQuestion = (Question) XMLParser.questionList
    .elementAt(quesNumber);

     title = DBMain.curQuestion.getTitle();
  String BlankSpace = "  ";
  String choice1 = "A.  " + DBMain.curQuestion.getChoice1() + "\n" + "  ";
  String choice2 = "B.  " + DBMain.curQuestion.getChoice2() + "\n" + "  ";
  String choice3 = "C.  " + DBMain.curQuestion.getChoice3() + "\n" + "  ";
  String choice4 = "D.  " + DBMain.curQuestion.getChoice4() + "\n" + "  ";
A: 

Thank you all for ur kind replies.Ok let me be more specific this time

static int[] c =new int[TestScreen.v.size()];

synchronized (disques) {
                // Vector data = new Vector();
                //data.addElement(TestScreen.v);
                 disques.setContents(c);
                 disques.commit();
                    }
             synchronized (disques) {
                    c = (int[])disques.getContents();
                    //System.out.println("valueee is.........."+data.size());
                }
             for (int i=0; i< c.length; i++) {

                    //c[i]=TestScreen.quesNumbernew[i];

                         if(quesNum.equals(c[i]+"")) {
                           xyz=quesNum[quesCount];
                         }
                       }
       //if (data.contains(quesNum)){

        //xyz=quesNum[quesCount];
        // }

       return xyz;

i am passing the value xyz to another page called TestScreen,where it is stored in a vector & then saving it in dis page only,so plz verify whether the saving is ok,& comparison logic is ok?if nt plz make the neccesary changes,will b thakful for ur repies

Arunabha Dutta Choudhury
please update your original question with updates instead of adding answers.
Romain Hippeau
Arunabha Dutta Choudhury