今日计划
继续app的开发
今日完成情况
- 搜索界面的绘制,以及逻辑代码的编写,可以根据备注信息查询某一条记录,点击搜索图标可以自动弹出键盘,同时可以模糊搜索。
首先在数据库管理类中添加,搜索的代码
/**
* 根据备注搜索收入或者支出的情况列表
*/
public static List<AccountBean> getAccountListByRemarkFromAccounttb (String beizhu) {
List<AccountBean> list = new ArrayList<>();
String sql = "select * from accounttb where beizhu like '%" + beizhu +"%'";
Cursor cursor = db.rawQuery(sql, null);
while (cursor.moveToNext()) {
int id = cursor.getInt(cursor.getColumnIndex("id"));
String typeName = cursor.getString(cursor.getColumnIndex("typeName"));
String bz = cursor.getString(cursor.getColumnIndex("beizhu"));
String time = cursor.getString(cursor.getColumnIndex("time"));
int sImageId = cursor.getInt(cursor.getColumnIndex("sImageId"));
int kind = cursor.getInt(cursor.getColumnIndex("kind"));
float money = cursor.getFloat(cursor.getColumnIndex("money"));
int year = cursor.getInt(cursor.getColumnIndex("year"));
int month = cursor.getInt(cursor.getColumnIndex("month"));
int day = cursor.getInt(cursor.getColumnIndex("day"));
AccountBean accountBean = new AccountBean(id, typeName, sImageId, bz, money, time, year, month, day, kind);
list.add(accountBean);
}
return list;
}
== 模糊搜索这样来写:==
String sql = "select * from accounttb where beizhu like '%" + beizhu +"%'";
搜索页面布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/grey_f3f3f3">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp">
<ImageView
android:id="@+id/search_iv_back"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:onClick="onClick"
android:layout_marginLeft="10dp"
android:src="@mipmap/it_back1"/>
<EditText
android:id="@+id/search_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/search_iv_back"
android:background="@drawable/dialog_btn_bg"
android:layout_centerVertical="true"
android:textSize="16sp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:layout_marginLeft="10dp"
android:hint