今天,是一个值得纪念的日子,是我小菜菜,手写的第一份博客,也不知道写点什么,那么,就写一个前段日子在公司新改的需求吧,其实挺简单的,我们的需求的呢,是这样的,搜索的内容呢 只需要在下面展示5个就可以,然后历史记录下面还要有一个搜索推荐,数据保存到本地 那么 我使用的是数据库,so,那么 我来看看 我是如何实现的,当然,方法大家可能都见过,只是一时之间想不起来而已了,好吧 ,说的太多了,我们来看代码
先看:
布局XML
主布局代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
tools:context=".activity.game.SearchGameActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="38dp"
android:background="@color/wankr_stand_title"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="29dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:background="@drawable/bg_white">
<EditText
android:id="@+id/search_edit_text"
android:layout_width="match_parent"
android:layout_height="29dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@null"
android:imeOptions="actionSearch"
android:singleLine="true"
android:textColor="#333333"
android:textCursorDrawable="@null"
android:textSize="13sp" />
<ImageView
android:id="@+id/search_iv_cancel"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="8dp"
android:src="@drawable/search_cancle" />
</RelativeLayout>
<TextView
android:id="@+id/search_tv_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:layout_marginRight="10dp"
android:layout_weight="0"
android:text="取消"
android:textColor="#ffffff"
android:textSize="12sp" />
</LinearLayout>
<ListView
android:id="@+id/search_result_game"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@null"
android:listSelector="#00000000"
android:scrollbars="none">
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/game_disable"
android:visibility="gone">
<ImageView
android:id="@+id/iv_nodata"
android:layout_width="120dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="65dp"
android:background="@color/game_disable"
android:src="@drawable/v1_2_img_data_empty"
android:visibility="gone" />
<ImageView
android:id="@+id/img_txt_no_data"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@+id/iv_nodata"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:src="@drawable/v1_2_txt_data_empty"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>
下面我们来写历史记录的布局,headview:
headview的布局,历史记录和搜索推荐是一起的
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/his_lin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/histotry_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="22dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="13dp"
android:layout_weight="9"
android:text="历史记录"
android:textColor="#999999"
android:textSize="15sp" />
<ImageView
android:id="@+id/pic_deleate"
android:layout_width="40dp"
android:layout_height="39dp"
android:padding="12dp"
android:src="@drawable/delate" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="21dp"
android:orientation="horizontal">
<TextView