예제 #1
0
        private void Delete(string keyword)
        {
            var result = SearchHistoryShared.DeleteSearchHistory(keyword, this);

            if (result)
            {
                list.Remove(keyword);
                adapter.NotifyDataSetChanged();
                fixedListView(list.Count);//重新设置listview的高度
            }
        }
예제 #2
0
        void initSearchHistory()
        {
            lv_searchHistory = FindViewById <ListView>(Resource.Id.lv_searchHistory);
            imgbtn_delete    = FindViewById <ImageButton>(Resource.Id.imgbtn_delete);
            tv_deleteAll     = FindViewById <TextView>(Resource.Id.tv_deleteAll);

            tv_deleteAll.Click += (s, e) =>
            {
                bool result = SearchHistoryShared.DeleteSearchHistory(this);
                if (result)
                {
                    lv_searchHistory.Visibility = ViewStates.Gone;
                    tv_deleteAll.Text           = "没有搜索记录";
                    tv_deleteAll.SetTextColor(Resources.GetColor(Resource.Color.lightBlack));
                }
            };
            Dictionary <string, DateTime> dict = SearchHistoryShared.GetSearchHistory(this);

            if (dict != null && dict.Count > 0)
            {
                tv_deleteAll.Visibility = ViewStates.Visible;
                list                 = dict.Select(s => s.Key).ToList();
                adapter              = new SearchHistoryAdapter <string>(this, list, Resource.Layout.item_listview_searchhistory);
                adapter.ActionDelte += (keyword) =>
                {
                    Delete(keyword);
                };
                lv_searchHistory.Adapter = adapter;
                fixedListView(list.Count);
                lv_searchHistory.ItemClick += (s, e) =>
                {
                    keyword = list[e.Position];
                    SearchResultActivity.Enter(category, keyword, true, this);
                };
            }
            else
            {
                tv_deleteAll.Visibility = ViewStates.Visible;
                tv_deleteAll.Text       = "没有搜索记录";
                tv_deleteAll.SetTextColor(Resources.GetColor(Resource.Color.lightBlack));
            }
        }
예제 #3
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.searchResult);
            var app = ((InitApp)ApplicationContext);

            if (app != null)
            {
                app.addActivity(this);
            }
            tv_question    = FindViewById <TextView>(Resource.Id.tv_question);
            tv_news        = FindViewById <TextView>(Resource.Id.tv_news);
            tv_kb          = FindViewById <TextView>(Resource.Id.tv_kb);
            tv_blog        = FindViewById <TextView>(Resource.Id.tv_blog);
            search_keyword = FindViewById <SearchView>(Resource.Id.search_keyword);
            _recyclerView  = FindViewById <RecyclerView>(Resource.Id.recyclerView);
            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            swipeRefreshLayout = FindViewById <SwipeRefreshLayout>(Resource.Id.swipeRefreshLayout);
            swipeRefreshLayout.SetColorScheme(Resource.Color.primary);
            swipeRefreshLayout.Refreshing = false;
            StatusBarUtil.SetColorStatusBars(this);
            category   = Intent.GetStringExtra("category");
            keyword    = Intent.GetStringExtra("keyword");
            startQuery = Intent.GetBooleanExtra("startquery", false);


            initCategoryClick();      //初始化category单击事件
            initCategoryByCategory(); //初始化category 选中的状态
            toolbar.SetNavigationIcon(Resource.Drawable.back_24dp);
            toolbar.NavigationClick += (s, e) =>
            {
                ActivityCompat.FinishAfterTransition(this);
            };
            swipeRefreshLayout.Refresh += (s, e) =>
            {
                swipeRefreshLayout.PostDelayed(() => {
                    swipeRefreshLayout.Refreshing = false;
                }, 1000);
            };
            _recyclerView.SetLayoutManager(new Android.Support.V7.Widget.LinearLayoutManager(this));

            //search_keyword.SubmitButtonEnabled = true; //默认为false 不显示提交按钮,是否启用提交按钮
            search_keyword.OnActionViewExpanded(); //手动展开SearchView输入框,初始可以点击输入的状态
                                                   //search_keyword.SetIconifiedByDefault(false); //默认是为true 不显示输入框键盘,默认提交按钮不显示,该属性设置为false,则直接展开输入框弹出键盘
                                                   // search_keyword.RequestFocus(); //将控件设置成可获取焦点状态,默认是无法获取焦点的,只有设置成true,才能获取控件的点击事件
                                                   //search_keyword.Focusable = true;
            search_keyword.ClearFocus();
            search_keyword.Focusable = true;
            if (!string.IsNullOrEmpty(keyword))
            {
                search_keyword.QueryHint = keyword;
            }
            search_keyword.FocusChange += (s, e) =>
            {
                System.Diagnostics.Debug.Write(e.HasFocus);
                if (e.HasFocus)
                {
                    SearchInputActivity.Enter(category, this);
                }
            };

            search_keyword.SetOnQueryTextFocusChangeListener(this);
            search_keyword.QueryTextSubmit += async(s, e) =>
            {
                keyword = search_keyword.Query.Trim();
                if (keyword == null || keyword.Length == 0)
                {
                    return;
                }
                SearchHistoryShared.SetSearchHistory(keyword, this);
                swipeRefreshLayout.Refreshing = true;
                await listSearchService((list) => {
                    swipeRefreshLayout.PostDelayed(() => {
                        swipeRefreshLayout.Refreshing = false;
                    }, 1000);
                    searchList = list;
                    initRecycler();
                });
            };

            if (startQuery)
            {
                initCategoryByCategory();
                SearchHistoryShared.SetSearchHistory(keyword, this);
                if (!string.IsNullOrEmpty(keyword))
                {
                    swipeRefreshLayout.Refreshing = true;
                    await listSearchService((list) => {
                        swipeRefreshLayout.PostDelayed(() => {
                            swipeRefreshLayout.Refreshing = false;
                        }, 1000);
                        searchList = list;
                        initRecycler();
                    });
                }
            }
        }