安卓使用SQLite实现简单的历史记录

本文介绍了如何在Android应用中使用SQLite数据库来实现历史记录功能。内容包括创建历史记录布局,添加删除按钮,实现历史记录适配器,以及通过历史记录工具类创建数据库表。同时,展示了如何在布局中适当地显示历史记录,并在软键盘弹出时保持可见。别忘了在使用前进行必要的初始化操作和记录保存。
摘要由CSDN通过智能技术生成

历史记录布局文件,一行文字加右边的删除按钮

<?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">

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/search_history_item_tv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@id/search_history_item_img"
            android:paddingBottom="10dp"
            android:paddingLeft="10dp"
            android:paddingRight="4dp"
            android:paddingTop="10dp"
            android:textColor="#333333"
            android:textSize="17sp" />

        <ImageView
            android:id="@+id/search_history_item_img"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="10dp"
            android:src="@drawable/clear" />

    </RelativeLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="#e2dbdb" />
</LinearLayout>

历史记录适配器


public class HistorySearchAdapter extends RecyclerView.Adapter<HistorySearchAdapter.ViewHolder>
        implements View.OnClickListener {

    private Context mContext;

    private OnItemClickListener mOnItemClickListener;//item点击监听接口

    private List<String> histotyList = new ArrayList<String>();

    public HistorySearchAdapter(Context context, List<String> histotyList) {
        this.mContext = context;
        this.histotyList = histotyList;
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private TextView nameTv;
        private ImageView deleteImg;
        private View itemView;

        public ViewHolder(View itemView) {
            super(itemView);
            nameTv = (TextView) itemView.findViewById(R.id.search_history_item_tv);
            deleteImg = (ImageView) itemView.findViewById(R.id.search_
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值