历史记录布局文件,一行文字加右边的删除按钮
<?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_