自动完成tableview作为弹出的钛机器人

时间:2015-09-09 09:34:28

标签: android titanium tableview

是否可以创建自动完成tableview作为弹出窗口,对于我按下的每个键,我应该弹出一个tableview,其结果显示在其中

            var searchfield = Ti.UI.createTextField({
    height : '50dp',
    hintText : 'TestName',
    //left : '1%',
    //  right : '1%',
    keyboardType : Ti.UI.KEYBOARD_DEFAULT,
    returnKeyType : Ti.UI.RETURNKEY_DEFAULT,
    borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
    color : 'black',
    backgroundColor : 'white',
    ////borderColor : theme_style,
    //maxLength : 10,
    width : Ti.UI.FILL,
        });

           var tableview = Ti.UI.createTableView({
    scrollable : true,
    //data : data,
    //search : search,
    //filterAttribute : "title",
    width : '100%',
    //left : '10dp',
    height : Ti.UI.SIZE,
    focusable : true,
    top : '0dp',
    separatorColor : '#666362',
    //filterAnchored : true
    //borderColor : 'red'
});
win.add(tableview);

           searchfield.addEventListener('change', function(e) {
    //searchfield.value = "    " + searchfield.value;
    //var x = searchfield.value.trim(searchfield.value);
    //hinttext.blur();

    //search.setValue(searchfield.value);
    //search.setValue(x);
    var rd = [];
    tableview.data = rd;
    tableview.setData(rd);
    var data = [];
    if (searchfield.value == "" || searchfield.value == "null") {
        //  cview.blur();
        cview.height = 0;
        //hinttext.height = Ti.UI.SIZE;
        var rd = [];
        tableview.data = rd;
        tableview.setData(rd);
    } else if (searchfield.value.length > 2) {
        var rd = [];
        tableview.data = rd;
        tableview.setData(rd);
        cview.height = Ti.UI.SIZE;
        tableview.height = Ti.UI.SIZE;
        //hinttext.height = 0;
        var loginReq = Titanium.Network.createHTTPClient();
        Ti.API.info(searchfield.value + "---" + center_id);
        var data = [];
        var params = {
            billingname : searchfield.value,
            centerid : center_id
        };
        loginReq.onload = function() {
            var json = this.responseText;
            var response = JSON.parse(json);
            Ti.API.info("Entered Onload");
            for (var i = 0; i < response.GetPriceCalculationResult.length; i++) {
                var row = Ti.UI.createTableViewRow({
                    title : response.GetPriceCalculationResult[i].Billingname,
                    //title : "   " + resultrows.fieldByName('BillingName'),
                    color : 'white',
                    //my_id : resultrows.fieldByName('ID'),
                    onPress : "press",
                    my_value : response.GetPriceCalculationResult[i].Billingname,
                    //borderColor : '#E6E6E6',
                    font : {
                        fontSize : '14dp',
                        fontWeight : 'bold',
                        fontFamily : 'BurnstownDam-Regular'
                    },
                    height : Ti.UI.SIZE,
                    top : '5dp',
                    my_amount : response.GetPriceCalculationResult[i].Amount
                    //borderRadius : '10dp'
                    //my_value : myvalues[i],
                    //title : myvalues[i]
                });
                data.push(row);
                //resultrows.next();
                //}
                //Ti.API.info("rows----"+ resultrows.fieldByName('BillingName')+"++++++++++++"+resultrows.length);
            }
            //resultrows.close();
            //}
            //tableview.search = search;
            tableview.data = data;
            cview.tableview = tableview;
            tableview.addEventListener('click', function(e) {
                if (e.source.onPress == "press") {
                    var mynew_id = e.source.my_id;
                    var mynew_value = e.source.my_value;
                    var my_newamount = e.source.my_amount;
                    Ti.API.info(mynew_value);
                    searchfield.value = mynew_value;
                    //search.value = mynew_value;
                    Ti.App.Properties.setString("myid", mynew_id);
                    //var createnewWindowback = require('ui/page1');
                    //  new createnewWindowback().open();
                    //win.close();
                    //var trip_id = Ti.App.Properties.getString("my_id", '');
                    Ti.App.Properties.setString("testvalue", mynew_value);
                    Ti.App.Properties.setString("amountvalue", my_newamount);
                    dummyfieldforamount.value = my_newamount;
                    Ti.API.info("The mynew_id and mynew_value are" + mynew_id + mynew_value + my_newamount);
                    cview.height = Ti.UI.SIZE;
                }
            });
        };
        loginReq.onerror = function(e) {
            Ti.API.info("Entered error");

            if (Titanium.Network.online == false) {
                var alertDialog = Titanium.UI.createAlertDialog({
                    title : 'Error',
                    message : 'You need an active internet connection to access this awesomeness...sad day.',
                    buttonNames : ['OK, forgive me'],
                });
                alertDialog.show();
            } else {
                alert("Cannot connect to host!");
            }
        };
        loginReq.open("POST", "http://your url");

        loginReq.setRequestHeader('Content-Type', 'application/json');
        loginReq.send(JSON.stringify(params));
        var rd = [];
        tableview.data = rd;
        tableview.setData(rd);
    }
});

autocomplete result above a text field like a pop

请帮忙,这是否有关于此的任何模块

0 个答案:

没有答案