Reputation: 106
Strange one here. I have a database with a fixtures table which holds all the fixtures for a sports teams season. I am trying to create the functionality to allow the manager of the team to edit a fixture. I am able to select all the fixtures and return them to the listview but when I try to perform a query based upon the match_date column, nothing happens.
public class EditSchedule extends AppCompatActivity {
public Button fixtureSearch;
public EditText fixtureDate;
public String searchDate;
ListView editMatch;
DBHelper dbHelper = new DBHelper(this);
SQLiteDatabase sqLiteDatabase;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_editfixture);
editMatch = (ListView) findViewById(R.id.listViewEditMatch);
fixtureDate = (EditText) findViewById(R.id.fixtureDateEditSearch);
searchDate = fixtureDate.getText().toString();
fixtureSearch = (Button) findViewById(R.id.fixtureSearchButton);
fixtureSearch.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
//populate listview with query result
//final Cursor cursor = dbHelper.getAllFixtures();
final Cursor cursor = dbHelper.getMatch(searchDate);
final FixtureAdapter fixtureAdapter = new FixtureAdapter(getApplicationContext(), cursor, 0);
editMatch.setAdapter(fixtureAdapter);
}
}
);
}
}
My getMatch method in DBHelper looks like this:
public Cursor getMatch(String date) {
SQLiteDatabase sqLiteDatabase = getWritableDatabase();
String[] match = {_ID, MATCH_DATE, MATCH_OPPONENT, MATCH_VENUE, MATCH_TIME};
return sqLiteDatabase.query(TABLE_FIXTURES, match, MATCH_DATE + " = '" + date + "'", null, null, null, null);
}
}
There is nothing at all in the logcat when I click the search button, and you can see EditSchedule class that I have commented out the getAllFixtures cursor which does work. Your help would be greatly appreciated.
Upvotes: 1
Views: 172
Reputation: 40136
I see that you are passing a datetime as String,
public Cursor getMatch(String date) { ... }
==
) its difficult because there are upto nanosecond precision limit which have to be matched when you are filtering.System.currentTimeMillis()
.Upvotes: 1