TPshop完整APP项目(含服务器源码)第三课 - 商城搜索功能.
看图如下:
功能描述: 点击顶部文本输入框弹出软键盘, 输入关键字后, 点击键盘上的"搜索"键后请求后台搜索API
并将结果展示在列表中.
结构分析: 自上而下, 顶部是一个自定义View的searchView ,接下来是一个后台设置的热词列表, 下面是一个搜索记录的listview
顶部SPSearchView
public class SPSearchView extends LinearLayout { private ImageView backImgv; private EditText searchEdtv; private SPSearchViewListener searchListener; /** * @param context * @param attrs */ public SPSearchView(Context context, AttributeSet attrs) { super(context, attrs); View view = LayoutInflater.from(context).inflate(R.layout.search_heard_view, this); searchEdtv = (EditText)view.findViewById(R.id.search_edtv); backImgv = (ImageView)view.findViewById(R.id.back_imgv); searchEdtv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (searchListener != null) { //searchListener.onSearchBoxClick(searchEdtv.getText().toString()); } } }); backImgv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (searchListener != null) searchListener.onBackClick(); } }); searchEdtv.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) { //响应键盘"搜索"键 if (actionId == EditorInfo.IME_ACTION_SEARCH) { notifyStartSearching(textView.getText().toString()); } return true; } }); } /** * 通知监听者 进行搜索操作 * @param text */ private void notifyStartSearching(String text){ if (searchListener != null) { searchListener.onSearchBoxClick(text); } } public void setSearchKey(String searchKey){ if (this.searchEdtv!=null && !SPStringUtils.isEmpty(searchKey)){ this.searchEdtv.setText(searchKey); } } public EditText getSearchEditText(){ return this.searchEdtv; } public void setSearchViewListener(SPSearchViewListener listener){ this.searchListener = listener; } public interface SPSearchViewListener{ public void onBackClick(); public void onSearchBoxClick(String keyword); } }
搜索界面Activity的实现:
布局文件:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <com.soubao.tpshop.view.SPSearchView android:id="@+id/search_view" android:layout_width="match_parent" android:layout_height="50dip" /> <ListView android:id="@+id/search_key_listv" android:layout_width="match_parent" android:layout_height="match_parent" android:divider="@color/separator_line" android:dividerHeight="1px" android:fadingEdge="none" android:fastScrollEnabled="false" android:footerDividersEnabled="false" android:headerDividersEnabled="false" android:layout_marginTop="50dip" android:layout_marginBottom="50dip" android:scrollbars="none" android:smoothScrollbar="true" /> <Button android:id="@+id/search_delete_btn" android:layout_width="match_parent" android:layout_height="@dimen/height_button" android:layout_alignParentBottom="true" android:layout_marginLeft="20dip" android:layout_marginRight="20dip" android:layout_marginBottom="10dip" style="@style/textStyle.Normal.black" android:text="@string/delete_history" android:background="@drawable/tag_button_bg_unchecked" android:layout_centerHorizontal="true"/> </RelativeLayout>
onCreate中设置自定义标题
@Override protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); }
搜索记录缓存到SharedPrefreences中
public void loadKey(){ mSearchkeys = new ArrayList<String>(); String searchKey = SPSaveData.getString(this, SPMobileConstants.KEY_SEARCH_KEY); if (!SPStringUtils.isEmpty(searchKey)){ String[] keys = searchKey.split(","); if (keys !=null) for(int i=0; i< keys.length; i++){ if (!SPStringUtils.isEmpty(keys[i])){ mSearchkeys.add(keys[i]); } } } } public void saveKey(String key){ String searchKey = SPSaveData.getString(this, SPMobileConstants.KEY_SEARCH_KEY); if (!SPStringUtils.isEmpty(searchKey) && !searchKey.contains(key)) { searchKey+=","+key; }else{ searchKey = key; } SPSaveData.putValue(this, SPMobileConstants.KEY_SEARCH_KEY, searchKey); }
完整源码下载地址: demo tpshop安卓源码下载
相关推荐
学习本项目源码需有vue基础方可继续,当然了有想学习小程序的,也建议学习本项目源码需,学会uni-app之后,原生小程序也可快速上手。 源码包括以下内容: 首页页面、 执行登录、缓存Token和用户信息、 路由拦截、...
安卓app开发项目-LumaQQ-Android qq 代码(源码).zip安卓app开发项目-LumaQQ-Android qq 代码(源码).zip安卓app开发项目-LumaQQ-Android qq 代码(源码).zip安卓app开发项目-LumaQQ-Android qq 代码(源码).zip安卓app...
学习本项目源码需有vue基础方可继续,当然了有想学习小程序的,也建议学习本项目源码需,学会uni-app之后,原生小程序也可快速上手。 源码包括以下内容: 首页页面、 执行登录、缓存Token和用户信息、 路由拦截、...
一个完整的手工艺电商app项目的IOS源码-handwork-ios
安卓app开发项目-语音朗读-语音识别-语音(源码).zip安卓app开发项目-语音朗读-语音识别-语音(源码).zip安卓app开发项目-语音朗读-语音识别-语音(源码).zip安卓app开发项目-语音朗读-语音识别-语音(源码).zip安卓app...
App Store 项目源码--咖啡读书iphone源码 附件是空的包, 下载请移步github appstore: https://itunes.apple.com/cn/app/ka-fei-du-shu/id661040207?mt=8 github:https://github.com/ygweric/kafeidushu
毕业设计基于Android的移动音乐App播放系统项目源码毕业设计基于Android的移动音乐App播放系统项目源码毕业设计基于Android的移动音乐App播放系统项目源码毕业设计基于Android的移动音乐App播放系统项目源码毕业设计...
源码列表: IT之家小程序版客户端(使用 Mpvue 开发,兼容 Web)ithome-lite-master.zip mpvue 仿网易严选mpvue-shop-master.zip mpvue-音乐播放器mpvue-music-master.zip mpvue性能测试与体验miniweibo-master....
安卓app开发项目-音乐播放器(源码).zip安卓app开发项目-音乐播放器(源码).zip安卓app开发项目-音乐播放器(源码).zip安卓app开发项目-音乐播放器(源码).zip安卓app开发项目-音乐播放器(源码).zip安卓app开发项目-音乐...
安卓app开发项目-绝对给力的源码,在线音乐播放器完整项目(源码).zip安卓app开发项目-绝对给力的源码,在线音乐播放器完整项目(源码).zip安卓app开发项目-绝对给力的源码,在线音乐播放器完整项目(源码).zip安卓app...
源码类型列表: IT之家小程序版客户端(使用 Mpvue 开发,兼容 Web)ithome-lite-master.zip mpvue 仿网易严选mpvue-shop-master.zip mpvue-音乐播放器mpvue-music-master.zip mpvue性能测试与体验miniweibo-master...
uview 商城中的 使用uniapp开发的一整套电商app的源码 uniapp开发 开源 app源码 电商app
uni-app完整版交互商城源码v3,免费共享,目录 store static pages components common uni.scss pages.json manifest.json main.js App.vue
功能:可以将网址打包封装成APK(暂不支持打包成IOS 应用),类似于变色龙打包APP,不过现在网上打包APP的都开始收费(100软妹币/年)和实名了 源码带安装教程和常见问题的解决方案,这只是一个demo(还达不到商用的地步,...
安卓app开发项目-在线词典源码(源码).zip安卓app开发项目-在线词典源码(源码).zip安卓app开发项目-在线词典源码(源码).zip安卓app开发项目-在线词典源码(源码).zip安卓app开发项目-在线词典源码(源码).zip安卓app...
安卓app开发项目-qiyi(源码).zip安卓app开发项目-qiyi(源码).zip安卓app开发项目-qiyi(源码).zip安卓app开发项目-qiyi(源码).zip安卓app开发项目-qiyi(源码).zip安卓app开发项目-qiyi(源码).zip安卓app开发项目-qiyi...
这是使用WeX5移动应用开发工具开发的一个H5 App,功能仿淘宝。全部源代码免费, 您可在线体验以下功能: 1)模仿淘宝的首页展现; 2)查看购物车; 3)宝贝搜索页; 4)宝贝列表和宝贝详情的展现; 还有其他功能...
干货!8套H5 App完整源码!果断收藏!-附件资源.txt
安卓app开发项目-MobileSale(源码).rar安卓app开发项目-MobileSale(源码).rar安卓app开发项目-MobileSale(源码).rar安卓app开发项目-MobileSale(源码).rar安卓app开发项目-MobileSale(源码).rar安卓app开发项目-...
安卓app开发项目-竖直SeekBar源码(源码).zip安卓app开发项目-竖直SeekBar源码(源码).zip安卓app开发项目-竖直SeekBar源码(源码).zip安卓app开发项目-竖直SeekBar源码(源码).zip安卓app开发项目-竖直SeekBar源码(源码...