搜索功能

YZY
Kk-juejuezi 3 years ago
parent cb55d6c4ac
commit cb504b6ae8

@ -18,6 +18,7 @@ package net.micode.notes.data;
import android.content.ContentValues;//就是用于保存一些数据string boolean byte double float int long short ...)信息,这些信息可以被数据库操作时使用。 import android.content.ContentValues;//就是用于保存一些数据string boolean byte double float int long short ...)信息,这些信息可以被数据库操作时使用。
import android.content.Context;//加载和访问资源。android中主要是这两个功能但是这里具体不清楚 import android.content.Context;//加载和访问资源。android中主要是这两个功能但是这里具体不清楚
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;//主要提供了对应于添加、删除、更新、查询的操作方法: insert()、delete()、update()和query()。配合content.values import android.database.sqlite.SQLiteDatabase;//主要提供了对应于添加、删除、更新、查询的操作方法: insert()、delete()、update()和query()。配合content.values
import android.database.sqlite.SQLiteOpenHelper;//用来管理数据的创建和版本更新 import android.database.sqlite.SQLiteOpenHelper;//用来管理数据的创建和版本更新
import android.util.Log; import android.util.Log;
@ -395,4 +396,21 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.TOP db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.TOP
+ " INTEGER NOT NULL DEFAULT 0"); + " INTEGER NOT NULL DEFAULT 0");
} }
public void dosearch(String querystring){//搜索时不区分大小写
Cursor cursor = null;
SQLiteDatabase db = mInstance.getReadableDatabase();
String query_sql_string = "select * from " + TABLE.DATA + " where content like " + "'%"+ querystring + "%'";
Log.i(TAG,query_sql_string);
cursor = db.rawQuery(query_sql_string,null);
if(cursor!=null)
{
while(cursor.moveToNext())
{
String content = cursor.getString(cursor.getColumnIndex("content"));
Log.i(TAG, content);
}
}
cursor.close();
}
} }

@ -78,6 +78,7 @@ import android.widget.Toast;
import net.micode.notes.R; import net.micode.notes.R;
import net.micode.notes.data.Notes; import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.TextNote; import net.micode.notes.data.Notes.TextNote;
import net.micode.notes.data.NotesDatabaseHelper;
import net.micode.notes.model.WorkingNote; import net.micode.notes.model.WorkingNote;
import net.micode.notes.model.WorkingNote.NoteSettingChangedListener; import net.micode.notes.model.WorkingNote.NoteSettingChangedListener;
import net.micode.notes.tool.DataUtils; import net.micode.notes.tool.DataUtils;
@ -250,7 +251,7 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
mWorkingNote = null; mWorkingNote = null;
if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) { if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) {
long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0); long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0);
mUserQuery = ""; mUserQuery = "";//要高亮的字符串
//如果用户实例化标签时系统并未给出标签ID //如果用户实例化标签时系统并未给出标签ID
/** /**
* Starting from the searched result * Starting from the searched result
@ -326,7 +327,14 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
getWindow().setSoftInputMode( getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
| WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); | WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
} else { }else if (TextUtils.equals(Intent.ACTION_SEARCH,intent.getAction())){//点击搜索按钮响应
String querystring = intent.getStringExtra(SearchManager.QUERY);//获取搜索框的字符
NotesDatabaseHelper dbhelper = new NotesDatabaseHelper(this);
dbhelper.dosearch(querystring);
finish();
return false;
}
else {
Log.e(TAG, "Intent not specified action, should not support"); Log.e(TAG, "Intent not specified action, should not support");
finish(); finish();
return false; return false;
@ -603,7 +611,8 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
menu.findItem(R.id.menu_alert).setVisible(false); menu.findItem(R.id.menu_alert).setVisible(false);
} else { } else {
menu.findItem(R.id.menu_delete_remind).setVisible(false); menu.findItem(R.id.menu_delete_remind).setVisible(false);
}if (mWorkingNote.getTopId() == 1){ }
if (mWorkingNote.getTopId() == 1){
menu.findItem(R.id.menu_top).setTitle("Cancel top"); menu.findItem(R.id.menu_top).setTitle("Cancel top");
}else { }else {
menu.findItem(R.id.menu_top).setTitle("Top"); menu.findItem(R.id.menu_top).setTitle("Top");
@ -1471,5 +1480,4 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
} }
return null; return null;
} }
} }

@ -555,7 +555,7 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
} }
} }
} }
//打开一个便签
private void openNode(NoteItemData data) { private void openNode(NoteItemData data) {
Intent intent = new Intent(this, NoteEditActivity.class); Intent intent = new Intent(this, NoteEditActivity.class);
intent.setAction(Intent.ACTION_VIEW); intent.setAction(Intent.ACTION_VIEW);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 92 B

Loading…
Cancel
Save