简体   繁体   中英

Maintain Focus with two textbox and button using Brightscript

I created a one Login Form in the bright script. It's following

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

TextBox 1 ' Here the focus is active I set by default in TextBox field active = true

TextBox 2 ' Here the press down key to active true

Button 1 ' Here again press down key to focus true

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Here, I maintain the 3 Items using 3 different key. Now I want to maintain the single key for all 3 items using the down key. Anyone idea to How to maintain Focus using Brightscript.

I used the one function for key handling It's here

function onKeyEvent(key as String, press as Boolean) as Boolean

.................

end function

Now, I maintained the key like I set TextBox Focus active in ByDefault to XML File.Now I apply Logic to below. First item focus set on XML file by default.

if key = "down" then 
       'Here Second item focus
       m.keypass.active = true ' Here work successfully First time
       if key = "down" and m.keypass.active = true and m.btnsub.active = false then
          'Here not maintain successfully its directly call here I press the down key.       
           m.keypass.active = false    
           m.btnsub.active = true 'Here third item focus is not maintained 

       end if
end if

I first-time press the down key It's working fine But its second time How handling the Focus. I used the same thing in Up key.

Here I am using "and" then the issue will happen is there any idea.

Pls, Check Here's an image really what I want to do. 在此处输入图片说明

Edited Post:

I handle with up and down key with below code. It's working But, Its only work in a single time.

 if key = "up" or key = "down"  
        if key = "down" 

          ?"here down key"

            if m.keypass.id = "instructpass" and m.keypass.active = true
                  ? "down key if part"
                  m.btngrp.setFocus(true)
                  m.keypass.active = false         
                  handled = true
            else if m.keyid.id = "instructid" and m.keyid.active = true 
                ?" down key else part"     
                m.keypass.active = true
                m.keyid.active = false
                handled = true
            else if m.btngrp.buttonSelected = 0
                m.keyid.active = true
                m.btngrp.setFocus(false)
                handled = true              
            end if 

            handled = true

       else if key = "up" 

         ? "here up key"

           if  m.keypass.active = true
                  ?"up key if part"
                  m.keyid.active = true
                  m.keypass.active = false
                  handled = true
           else if  m.keyid.active = true
                  ?"id key"
                  m.btngrp.setFocus(true)
                  m.btngrp.focusButton = 1
                  m.keyid.active = false        
                  handled = true

           else if m.btngrp.focusButton = 0 and m.btngrp.buttonSelected = 0
                ?"up key else part"
                m.keypass.active = true
                m.keypass.setFocus(true)     
                m.btngrp.setFocus(false)
                handled = true

            end if

                handled = true
        end if
        handled = true
end if   

Thank you.

Check here .

You should use .setFocus(true) and .hasFocus(), which are available to most renderable nodes such as TextEditBox and Button.

Eg

if key = "down" then 
    if textBox1.hasFocus() then 
        textBox2.setFocus(true)
    elseif textBox2.hasFocus() then 
        button.setFocus(true)
    end if
end if

if key = "up" then 
    if button.hasFocus() then 
        textBox2.setFocus(true)
    elseif textBox2.hasFocus() then 
        textBox1.setFocus(true)
    end if
end if

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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