title: How to implement a queue in android main activity
body: <p>this is my first time to post here because I'm that desperate. Anyway, I have this project and I'm having trouble in implementing the queue. My android app is a rebus puzzle implemented using a queue. At the start of the game, I want to enqueue all the nodes containing the answer to each puzzle. Then a photo of a puzzle will show and a textfield and a button on where the user can input the answer. My problem is I don't know how to implement the queue in java. So that when I press the button to submit the answer it will dequeue the current node and then the level will be incremented and at the same time a different picture will show up. But if the user's answer is wrong then it will just stay at the current puzzle.</p>
  
  <p>Here's my code for the puzzle node:</p>
  
  <pre><code>    package com.project.rebus;
  
      public class PuzzleNode {
  
      private String answer;
      private PuzzleNode next;
  
      public PuzzleNode(String answer, PuzzleNode next) {
          this.answer = answer;
          this.next = next;
      }
  
      public String getAnswer() {
          return answer;
      }
  
      public void setAnswer(String answer) {
          this.answer = answer;
      }
  
      public PuzzleNode getNext() {
          return next;
      }
  
      public void setNext(PuzzleNode next) {
          this.next = next;
      }
  }
  </code></pre>
  
  <p>Here's my code for the Queue:</p>
  
  <pre><code>package com.project.rebus;
  
  public class PuzzleQueue {
    PuzzleNode head;
    PuzzleNode tail;
    int size;
    int score;
  
   public PuzzleQueue() {
      head = null;
      tail = null;
      size = 0;
      score = 0;
  }
  
   public int size() {
      return size;
  }
  
  public boolean isEmpty() {
      if(head == null)
          return true;
      else
         return false;
  }
  
   public void enqueue (PuzzleNode data)
  {
  
      PuzzleNode n = new PuzzleNode(data.getAnswer(), null);
  
      if (tail != null)
          tail.setNext(n);
      tail = n;
  
      if (head == null)
          head = n;
  
      size++;
  }
  
   public String dequeue ()
  {
       String temp;
  
      temp =  head.getAnswer();
      head = head.getNext();       
      size--;
  
       if (size == 0)
          tail = null;
  
      return temp;
  }
  
   public String front()
   {
       return head.getAnswer();
   }
  
  public boolean compare(String answer) {
      if (head.getAnswer().equalsIgnoreCase(answer))
          return true;
      else return false;
  }
  }
  </code></pre>
  
  <p>Here's my code for the Activity One in Android on where I will implement the Queue:</p>
  
  <pre><code>   package com.project.rebus;
  
     import android.os.Bundle;
     import android.app.Activity;
     import android.view.Menu;
     import android.view.View;
     import android.widget.EditText;
     import android.widget.ImageView;
     import android.widget.TextView;
  
  
    public class RebusActivityOne extends Activity {
  
   PuzzleQueue rebus = new PuzzleQueue();
   PuzzleNode p1 = new PuzzleNode("for instance", null);
   PuzzleNode p2 = new PuzzleNode("too funny for words", null);
   PuzzleNode p3 = new PuzzleNode("once in a blue moon", null);
  
  int level = 1;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_rebus_activity_one);
  
      ImageView image = (ImageView) findViewById (R.drawable.r1);
  
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.rebus_activity_one, menu);
      return true;
  }
  
  
  public void button (View view) {
      rebus.enqueue(p1);
          rebus.enqueue(p2);
          rebus.enqueue(p3);
  
          ImageView image = null;
  
          while (level &lt;= 3) {
              if (level == 1) {
                  image = (ImageView) findViewById (R.id.r1);
              }else if (level == 2) {
                  image.setImageResource(R.drawable.r2);
              }else if (level == 3) {
                  image.setImageResource(R.drawable.r3);
              }
  
              boolean correct = false;
              do {
                  EditText answerField = (EditText)findViewById(R.id.answerField);
                  String answer = answerField.getText().toString();
                  if (rebus.compare(answer) == true) {
                      correct = true;
                      rebus.dequeue();
                      level++;
                  }//else System.out.println("Wrong answer");
              }while(correct == false);
          }
  }
  
  
  }
  </code></pre>
  
  <p>I keep on getting errors on the button code. IDK WHAT TO DO ANYMORE. HUHUHU.
  Any help will be very much appreciated.</p>