This is our main class to get information from the database. We are trying to get the values of the "name" column in the "barcode" database that we have created. Right now, we are not able to get the desired value but values as "a, b, c, d, ..." (such as; it returns "a" when we ask for the 1st one, it return "b" when we ask for the second one in the "name" column) value with the cursor.getString
method
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DataBaseHelper myDbHelper = new DataBaseHelper(this);
myDbHelper = new DataBaseHelper(this);
try {
myDbHelper.createDatabase();
} catch (IOException ioe) {
throw new Error("Unable to create database");
}
try {
myDbHelper.openDataBase();
} catch(SQLException sqle){
throw sqle;
}
Cursor cursor = myDbHelper.getAllAccounts();
String[] values = new String[6];
int i=0;
//take into the array from the database
while(cursor.moveToNext()){
values[i]= cursor.getString(cursor.getColumnIndex("name"));
i++;
}
cursor.close();
//Write to textview
TextView youtextview = (TextView) findViewById(R.id.textView1);
youtextview .setText(values[2]);
}
}