简体   繁体   English

在Titanium android tableview上切换搜索栏

[英]toggle searchbar on Titanium android tableview

I have a tableview with searchbar 我有一个带有搜索栏的表格视图

var tv = Titanium.UI.createTableView ({
            data: official_list,
            filterAttribute: 'title',
            backgroundColor : '#fff',
            search: search,
            searchHidden:false,
            top: '50dp'
        });

I want the searchbar to be hidden initially and only shown when searchbutton is pressed. 我希望搜索栏最初被隐藏,并且仅在按下searchbutton时显示。 I am using the following code for that 我为此使用以下代码

searchButton.addEventListener('click', function(_e) {
        search.visible = !search.visible;
        if(search.visible) {
            search.focus();
            self.softKeyboardOnFocus = 0;
        }
        else {
            Ti.UI.Android.hideSoftKeyboard();
        }
    });

The problem i am having is, even though the search gets hidden, a blank space remains in the place of searchbar. 我遇到的问题是,即使搜索被隐藏,在搜索栏的位置仍会留有空白。

I tried animating the coordinates of the tableview but that overrides the navigation bar and the blank space still remains. 我尝试使tableview的坐标动画化,但是这会覆盖导航栏,并且仍然保留空白。 Is there anyway i can toggle the searchbar (by removing the white space also ? ). 无论如何,我是否可以切换搜索栏(也可以通过删除空白?)。

Please help! 请帮忙!

I solved the problem by creating 2 searchBar and making the searchBar in tableview coordinates out of scope. 我通过创建2 searchBar并使tableview中的searchBar坐标超出范围来解决了该问题。 The searchbar attached to the tableview is made 1dp. 附加到表格视图的搜索栏设为1dp。

var search = Titanium.UI.createSearchBar({
        barColor:'#000', 
        showCancel:false,
        top: -50,
        height:'45dp',          
        hidden: true,
        visible: false,   
        softKeyboardOnFocus : Titanium.UI.Android.SOFT_KEYBOARD_DEFAULT_ON_FOCUS     
    }); 

var search_table = Titanium.UI.createSearchBar({
        barColor:'#000', 
        showCancel:false,
        height:'1dp',           
        hidden: true,
        visible: false,   
    });     

Now i can animate searchBar (search). 现在,我可以为searchBar(搜索)设置动画了。

    search.visible = !search.visible;
            if(search.visible) {
                search.focus();
                self.softKeyboardOnFocus = 0;
                search.animate({
                     top: '50dp',
                     duration : 500,
                     delay : 0,  
                     curve: Titanium.UI.ANIMATION_CURVE_EASE_IN                  
                });
                tv.animate({
                     top: '90dp',
                     duration : 500,
                     delay : 0,                  
                     curve: Titanium.UI.ANIMATION_CURVE_EASE_IN
                });
            }
            else {
                Ti.UI.Android.hideSoftKeyboard();
                tv.animate({
                     top: '50dp',
                     duration : 500,
                     delay : 0,                  
                     curve: Titanium.UI.ANIMATION_CURVE_EASE_OUT
                });
            }
    });

and pass the values from searchBar to search_table ( better way was to write query for each search but i have more than 7 and instead choose passing the value to tableview.search ) 并将值从searchBar传递到search_table(更好的方法是为每个搜索编写查询,但是我有7个以上,而是选择将值传递给tableview.search)

    search.addEventListener('change', function(e) {
        search_table.value = e.value;
    });

I think your solution do not work because the tableview is the immediate children of the window. 我认为您的解决方案不起作用,因为tableview是窗口的直接子级。

It should work if you enclose the tableview with another view, and then animate the tableview within the enclosing view to hide the search bar. 如果您用另一个视图将表格视图包围起来,然后在该表格视图中对表格视图进行动画处理以隐藏搜索栏,则该方法应该起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM