title: Android - Getting data from db
body: <p>I am making an animeList-app, like the website myAnimeList.</p>
  
  <p>My problem is that the data that I show in the app from my db is "random". Some data doesn't show up or isn't right and if I click on an item (like the anime "One Piece") Toast.makeText(myAnime_completed.get(position).getName()); will give me a completely random item from the db. </p>
  
  <p>I have a databaseHelper where I load data. </p>
  
  <pre><code>        //CREATE TABLE MYANIME
          String CREATE_TABLE_MYANIME = "CREATE TABLE myAnime (" +
                  "id INTEGER PRIMARY KEY AUTOINCREMENT," +
                  "name TEXT," +
                  "description TEXT," +
                  "episodes INTEGER," +
                  "genre TEXT," +
                  "rating INTEGER," +
                  "episodesWatched INTEGER," +
                  "stateId INTEGER)";
          db.execSQL(CREATE_TABLE_MYANIME);       
  
  private void insertMyAnime(SQLiteDatabase db) {
          db.execSQL("INSERT INTO myAnime (name, description, episodes, genre, rating, episodesWatched, stateId) VALUES ('One Piece', 'GUUD', 700, 'brut', 0, 50, 2);");
          db.execSQL("INSERT INTO myAnime (name, description, episodes, genre, rating, episodesWatched, stateId) VALUES ('Death Note', 'GUUD TUU', 35, 'thriller', 0, 50, 1);");
          db.execSQL("INSERT INTO myAnime (name, description, episodes, genre, rating, episodesWatched, stateId) VALUES ('Fairy Tail', 'GUUD TUU', 35, 'thriller', 0, 50, 2);");
          db.execSQL("INSERT INTO myAnime (name, description, episodes, genre, rating, episodesWatched, stateId) VALUES ('Naruto', 'GUUD TUU', 35, 'thriller', 0, 50, 1);");
          db.execSQL("INSERT INTO myAnime (name, description, episodes, genre, rating, episodesWatched, stateId) VALUES ('Bleach', 'GUUD TUU', 35, 'thriller', 0, 50, 3);");
          db.execSQL("INSERT INTO myAnime (name, description, episodes, genre, rating, episodesWatched, stateId) VALUES ('No Game No Life', 'GUUD TUU', 35, 'thriller', 0, 50, 3);");
          db.execSQL("INSERT INTO myAnime (name, description, episodes, genre, rating, episodesWatched, stateId) VALUES ('Kill la Kill', 'GUUD TUU', 35, 'thriller', 0, 50, 3);");
      }
  </code></pre>
  
  <p>After this I try to seperate the data in different catagories: watching, completed, on hold, dropped and plan to watch. </p>
  
  <pre><code>public MyAnime getMyAnimeByID(int animeId) {
          SQLiteDatabase db = this.getReadableDatabase();
          MyAnime myAnime = new MyAnime();
          Cursor cursor = db.query("myAnime", new String[] { "id", "name",
                  "description", "episodes", "genre", "rating",
                  "episodesWatched", "stateId" }, "id = ?",
                  new String[] { String.valueOf(animeId) }, null, null, null);
          if (cursor.moveToFirst()) {
              myAnime = new MyAnime(cursor.getInt(0), cursor.getString(1),
                      cursor.getString(2), cursor.getInt(3), cursor.getString(4),
                      cursor.getInt(5), cursor.getInt(6), cursor.getInt(7));
          }
          cursor.close();
          db.close();
          return myAnime;
      }
  
      public List&lt;MyAnime&gt; getMyAnimes_watching() {
          List&lt;MyAnime&gt; myAnimeList = new ArrayList&lt;MyAnime&gt;();
          SQLiteDatabase db = this.getReadableDatabase();
  
          Cursor cursor = db.query("myAnime", 
                  new String[] { "id" }, "stateId = ?", 
                  new String[] { String.valueOf(1)}, null, null, null);
  
          if (cursor.moveToFirst()) {
              do {
                  myAnimeList.add(getMyAnimeByID(cursor.getInt(0)));
              } while (cursor.moveToNext());
          }
  
          cursor.close();
          db.close();
          return myAnimeList;
      }
  
      public List&lt;MyAnime&gt; getMyAnimes_completed() {
          List&lt;MyAnime&gt; myAnimeList = new ArrayList&lt;MyAnime&gt;();
          SQLiteDatabase db = this.getReadableDatabase();
          Cursor cursor = db.query("myAnime", new String[] { "id" },
                  "stateId = ?", new String[] { String.valueOf(2)}, null, null,
                  null);
          if (cursor.moveToFirst()) {
              do {
                  myAnimeList.add(getMyAnimeByID(cursor.getInt(0)));
              } while (cursor.moveToNext());
          }
          cursor.close();
          db.close();
          return myAnimeList;
      }
  </code></pre>
  
  <p>Then in the activity I get the data from the db:</p>
  
  <pre><code>//FILL LISTVIEW COMPLETED
      final List&lt;MyAnime&gt; myAnime_completed = db.getMyAnimes_completed();    
      ArrayAdapter&lt;MyAnime&gt; adapter_completed = new ArrayAdapter&lt;MyAnime&gt;(this, android.R.layout.simple_list_item_1, myAnime_completed);
  
      ListView lvCompleted = (ListView) findViewById(R.id.myAnime_completed);
      lvCompleted.setAdapter(adapter_completed);
  
      lvCompleted.setOnItemClickListener(
              new AdapterView.OnItemClickListener() {
                  @Override
                  public void onItemClick(AdapterView&lt;?&gt; parentView, 
                              View childView, int position, long id) {
  
                      show(myAnime_completed.get(position).getName());
                      //goToNextActivity(myAnime_completed.get(position).getId());
  
                  }
      });
  </code></pre>
  
  <p>To be honest, I'm a student and I realise that this could be very easy to solve, but for someone with not much expierience this is a braintwister.</p>
  
  <p>I really hope someone can help me!</p>