title: how to get ID Value from sqlite database (android studio java)
body: <p>when i try to click some name from listview, i want it to return the ID from its name(in Toast Text), but i always getting result "0" wherever i click a name in listview, can you help me fix my code?, thanks</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>public void toastMessage(String message) {
      Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
  }
  
  public void toastMessageInt(int message) {
      Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
  }
  
  public void refreshPage() {
      listView = findViewById(R.id.listView);
      ArrayList&lt;String&gt; arrayList = new ArrayList&lt;&gt;();
      Cursor getView = myDB.showListView();
  
      while (getView.moveToNext()) {
          arrayList.add(getView.getString(1));
          ListAdapter listAdapter = new ArrayAdapter&lt;&gt;(this, android.R.layout.simple_list_item_1,arrayList);
          listView.setAdapter(listAdapter);
      }
  
      listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              String name = parent.getItemAtPosition(position).toString();
              int data = myDB.GetId(name);
              String dataToString = String.valueOf(data);
              toastMessage(dataToString); //here always return "0"
          }
      });
  }
  </code></pre>
  
  <p>DatabaseHelper.java</p>
  
  <pre><code>public void onCreate(SQLiteDatabase db) {
      db.execSQL("create table notepadData(id integer primary key autoincrement, notepad text)");
  }
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      db.execSQL("drop table if exists notepadData");
      onCreate(db);
  }
  
  public int GetId(String currentNote) {
      SQLiteDatabase myDB = this.getWritableDatabase();
      Cursor getNoteId = myDB.rawQuery("select id from notepadData where notepad = '"+currentNote+"'",null);
      return getNoteId.getColumnIndex("id");
  }
  </code></pre>