title: Retrieving data from SQLite database and display it into ListView -android
body: <p>I created a database(mydb) with a table(student) in the onCreate function and then entered values dynamically using a button click.Now I want to retrieve all the data from the table student on a button click and display it into <strong>listview</strong>.</p>
  
  <pre><code>public class MainActivity extends Activity        
          {
  
          String name, phone;
              SQLiteDatabase db;
  
              @Override
              protected void onCreate(Bundle savedInstanceState) 
              {
                  super.onCreate(savedInstanceState);
                  setContentView(R.layout.activity_main);
                  db=openOrCreateDatabase("mydb", MODE_PRIVATE, null);
                  db.execSQL("CREATE TABLE IF NOT EXISTS student(dbname VARCHAR, dbphone VARCHAR);");
  
              }
  
              public void btnaddtodb(View v)
              {
                  EditText edtxtname = (EditText)findViewById(R.id.edtxtname);
                  EditText edtxtphone = (EditText)findViewById(R.id.edtxtphone);
  
                  name=edtxtname.getText().toString();
                  phone=edtxtphone.getText().toString();
  
                  db.execSQL("INSERT INTO student values('"+name+"','"+phone+"');");
  
                  edtxtname.setText("");
                  edtxtphone.setText("");
  
                  }
            }
  </code></pre>