Been searching and using all the resources here but nothing seems to work with my project.
i need to retrieve a random data upon shaking the device.
i already have my shake detection. my problem is i cant retrieve a random data.
tested on a device. the application crashes.
mainactivity.java
DataSource DS = new DataSource(this);
public void onShake(float force) {
// Called when Motion Detected
Toast.makeText(getBaseContext(), "Motion detected",
Toast.LENGTH_SHORT).show();
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// Do something after 5s = 5000ms
TextView text = (TextView) findViewById(R.id.textView1);
text.setText(DS.getRandomQuote());
}
}, 2000);
public String getRandomQuote() {
Cursor c = database.query(MysqLiteHelper.TABLE_COMMENTS,
new String[] { MysqLiteHelper.COLUMN_COMMENT}, null, null, null, null, "ORDER BY RANDON() LIMIT 1");
if(c.moveToFirst())
return c.getString(c.getColumnIndex(MysqLiteHelper.COLUMN_COMMENT));
else
return "nothing";
}
Already Read:
How can select random data from database and display in textview?
and
How can select random data from database and display in textview?
but doesn't work for me