0

私は次のことをします

テキスト フィールドをタップするとピッカーが表示され、テキスト フィールドの背景画像が変更されます。

その人がピッカーを使い終わったら (「完了」をクリックします)、テキスト フィールドの背景を白に戻します。

テキスト フィールドをもう一度クリックすると、ピッカーが表示されても背景画像が変更されません。

私に何ができる?テキストフィールドをクリックしてピッカーが表示されるたびに、テキストフィールドが緑色の背景に変更され続けるようにしたい. そして、タップすると白に戻り、ピッカーが消えます。

tf1.addEventListener('focus', function(e) {
    Titanium.API.info('Triggered focus on date txtField');

    tf1.setBackgroundImage('../images/selected.gif');

    Titanium.API.info(tf1.backgroundImage);

    var winDatePicker1 = Titanium.UI.currentWindow;

    var minDate = new Date();
    minDate.getFullYear();
    minDate.getMonth();
    minDate.getDate();

    var maxDate = new Date();
    maxDate.setFullYear(2018);
    maxDate.setMonth(9);
    maxDate.setDate(30);

    var datePicker = Ti.UI.createPicker({
        type : Ti.UI.PICKER_TYPE_DATE_AND_TIME,
        minDate : minDate,
        maxDate : maxDate,
        bottom : 0,
        minuteInterval : 10
    });

    var tview = Ti.UI.createView({
        height : '100%',
        width : '100%',
        top : 0,
        backgroundColor : 'transparent'
    });

    var done1 = Ti.UI.createImageView({
        title : '',
        width : 80,
        right : 12,
        height : 40,
        image : '../images/done.gif',
    });

    var toolbar1 = Ti.UI.createView({
        height : 43,
        backgroundImage : '../images/toolbar.gif',
    });

    toolbar1.add(done1);

    done1.addEventListener('click', function() {
        tf1.backgroundImage = '';
        toolbar1.hide();
        datePicker.hide();
        tview.hide();
    });

    tview.addEventListener('click', function() {
        toolbar1.hide();
        datePicker.hide();
        tview.hide();
    });

    // turn on the selection indicator (off by default)
    datePicker.selectionIndicator = true;

    datePicker.addEventListener('change', function(e) {

        Titanium.API.info('E value = ' + e.value);

        var pickerDate = e.value;

        var day = pickerDate.getDate();
        day = day.toString();

        if (day.length < 2) {
            day = '0' + day;
        }

        var month = pickerDate.getMonth();
        month = month + 1;
        month = month.toString();

        if (month.length < 2) {
            month = '0' + month;
        }

        var year = pickerDate.getFullYear();
        var hr = pickerDate.getHours();
        var min = pickerDate.getMinutes();

        if (hr < 10) {
            hr = '0' + hr;
        }

        if (min < 10) {
            min = '0' + min;
        }

        var datestr = '';

        if (hr >= 12) 
        {
            datestr += ' ' + (hr == 12 ? hr : hr - 12) + ':' + min + ' PM';
        } else {
            datestr += ' ' + hr + ':' + min + ' AM';
        }

        var newdate = month + "/" + day + "/" + year + datestr;

        Titanium.API.info('converted value = ' + newdate);

        tf1.setValue(newdate);

    });

    tview.add(datePicker);
    tview.add(toolbar1);

    winDatePicker1.add(tview);

    winDatePicker1.show({
        view : tf1,
        animated : true
    });

});
4

1 に答える 1

0
make setVisible(true) or setVisible(false)

show() and hide() will not give proper toggle at some conditions.
于 2012-11-07T17:03:12.023 に答える