我正在尝试输入代码以便能够在数据已存在于 sqlite 中时禁用该按钮。但我却发现了这个错误!你能帮我找到解决方案吗?
public boolean isExist(MovieFav movie) {
sqLiteDatabase = dbHelper.getReadableDatabase();
String QUERY = "SELECT * FROM " + TABLE_MOVIE + " WHERE " + _ID + "=" + movie.getTitle();
Cursor cursor = sqLiteDatabase.rawQuery(QUERY, null);
if (cursor.getCount() <= 0) {
cursor.close();
return false;
}
cursor.close();
return true;
}
这是代码
@Override
public boolean onCreateOptionsMenu(Menu menu){
if (movieFavHelper.isExist(movieFav)){
btnSaveMov.setEnabled(false);
} else {
btnSaveMov.setEnabled(true);
}
return super.onCreateOptionsMenu(menu);
}
public void onClick(View view) {
if (view.getId() == R.id.btn_love) {
String titles = tv_title.getText().toString().trim();
String overview = tv_overview.getText().toString().trim();
String release_date = tv_release.getText().toString().trim();
String vote_average = tv_vote_average.getText().toString().trim();
String url_poster = tv_url_image.getText().toString().trim();
movieFav.setTitle(titles);
movieFav.setOverview(overview);
movieFav.setRelease_date(release_date);
movieFav.setVote_average(vote_average);
movieFav.setPoster_path(url_poster);
Intent intent = new Intent();
intent.putExtra(SEND_MOVIE_FAV, movieFav);
intent.putExtra(SEND_POSITION, position);
if (!isInsert) {
if (!movieFavHelper.isExist(movieFav)) {
long result = movieFavHelper.insertMovie(movieFav);
if (result > 0) {
setResult(RESULT_ADD, intent);
Toast.makeText(DetailMovieActivity.this, getString(R.string.success_add), Toast.LENGTH_SHORT).show();
finish();
}
胡子哥哥
相关分类