这里很奇怪。我有一个数据库,有一个固定装置表,可以容纳运动队赛季的所有赛程。我正在尝试创建允许团队经理编辑灯具的功能。我可以选择所有灯具并将它们返回到列表视图,但是当我尝试根据match_date列执行查询时,没有任何反应。
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);
}
}
);
}
}
我在DBHelper中的getMatch方法如下所示:
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);
}
}
当我单击搜索按钮时,logcat中根本没有任何内容,你可以看到我已经注释掉了getAllFixtures游标的EditSchedule类。非常感谢您的帮助。
答案 0 :(得分:1)
我看到你将日期时间传递为String,
public Cursor getMatch(String date) { ... }
==
),这很困难,因为在过滤时必须匹配高达纳秒的精度限制。System.currentTimeMillis()
通常可以获得,这总是一种很好的做法。