2011-10-12 1 views
8

Ho un modulo con alcuni campi di input. Quindi voglio navigare tra i campi con il pulsante successivo ma funziona solo quando il tipo di campo di input è "numero". Con type = "text" non lo fa!Perché la visualizzazione Web di Android mostra "Avanti" nella tastiera solo se type = "number" e non con type = "text"?

Si tratta di un bug in Android 3.2.1?

I miei campi di input sono così:

<input type="text" name="..." .... /> --> keyboard "Go" 
<input type="text" name="..." .... /> --> keyboard "Go" 
<input type="number" name="..." .... /> --> here it shows the "Next" button on the keyboard 
<input type="text" name="..." .... /> --> keyboard "Go" 

risposta

0

Suppongo è necessario specificare che il vostro ingresso non è un ingresso più righe, in caso contrario, il prossimo è sostituito dal seguente

+0

ho messo un esempio nella mia interrogazione. – user930141

0

Quando webkit rende quelli di ingresso campi, li converte in una classe chiamata android.webkit.WebTextView che determina come dovrebbe apparire la softkey e non sembra essere un buon modo per sovrascrivere l'ImeOptions impostato dalla classe WebTextView

2

DennisA è giusto per Android 4 .0 e sotto.

In breve questo non è un bug ma purtroppo come lo ha implementato google (preferirei un GO coerente per tutte quelle chiavi in ​​modo da poter impedire l'azione predefinita in JavaScript).

Con Android 4.1 (Jellybean), è possibile modificare il comportamento predefinito per WebViewInputConnection estendendo: https://github.com/android/platform_frameworks_base/blob/master/core/java/android/webkit/WebViewClassic.java#L379

(hackery coinvolti)

+0

Non sono chiaro su come fare questo lavoro. Sia WebViewInputConnection sia l'input necessario WebViewCore.TextFieldInitData sembrano essere fuori portata. Hai un esempio di come hai fatto questo? Grazie. –

+1

quel collegamento è morto ora; ITYM https://github.com/android/platform_frameworks_base/blob/jb-release/core/java/android/webkit/WebViewClassic.java#L362 ma il fatto che sia morto mi fa dubitare che funzionerà in 4.2: / – Chani

-1

Mi auguro che possa aiutare gli altri. L'ho gestito in javascript. Ho scritto il codice javascript per mostrare il prossimo pulsante sul lato destro di ogni input e selezionare i controlli. Quando l'utente tocca il pulsante successivo, passa al controllo successivo. Ho scritto seguente codice per questo:

 //Move to next crontrol bock 
    var MOVE_TO_NEXT_ID = 'aNext86332'; 
    function bindNext() { 
     var allTags = document.getElementsByTagName('*'); 
     for (var intEle = 0; intEle < allTags.length; intEle++) { 
      if (allTags[intEle].tagName.toLowerCase() == 'input' || allTags[intEle].tagName.toLowerCase() == 'textarea' || allTags[intEle].tagName.toLowerCase() == 'select') { 
       allTags[intEle].addEventListener("focus", function() { 
        //find next input 
        var nextFocus = null; 
        var all = document.getElementsByTagName('*'); 
        var flag = 0; 
        for (var j = 0 ; j < all.length; j++) { 
         if (flag == 1) { 
          if (all[j].tagName.toLowerCase() == 'input' || all[j].tagName.toLowerCase() == 'textarea' || all[j].tagName.toLowerCase() == 'select') { 
           var t = allTags[j]; 
           try { 
            if (t.style.display == 'none') { 
             continue; 
            } 
            else if (t.parentElement.style.display == 'none') { 
             continue; 
            } 
            else if (t.parentElement.parentElement.style.display == 'none') { 
             continue; 
            } 
            else if (t.parentElement.parentElement.parentElement.style.display == 'none') { 
             continue; 
            } 
            else { 
             nextFocus = allTags[j]; 
             break; 
            } 
           } 
           catch (e) { } 
          } 
         } 
         if (this.id == all[j].id) { 
          flag = 1; 
         } 
        } 
        showNext(this, nextFocus); 

       }); 
       allTags[intEle].addEventListener("blur", function() { 
        removeNext(this); 
       }); 
      } 
     } 
    } 
    function moveToNextControl(me, nextObj) { 
     if (nextObj != null) { 
      nextObj.focus(); 
      nextObj.scrollIntoView(true); 
     } 
    } 
    function removeNext(me) { 
     setTimeout(function() { 
      try { 
       var next = document.getElementById(MOVE_TO_NEXT_ID); 
       me.parentElement.removeChild(next); 
      } 
      catch (e) { } 
     }, 300); 
    } 
    function showNext(me, nextObj) { 
     setTimeout(function() { 
      var next = document.createElement("a"); 
      next.className = 'btn btn-default animated fadeIn'; 
      next.innerHTML = 'Next'; 
      next.style.position = 'absolute'; 
      next.style.zIndex = 1; 
      next.style.top = '0'; 
      next.id = MOVE_TO_NEXT_ID; 
      next.style.left = (me.clientWidth - 40) + 'px'; 
      next.addEventListener("click", function() { 
       moveToNextControl(me, nextObj); 
      }); 
      me.parentElement.appendChild(next); 
     }, 500); 

    } 
    //End of Move to next crontrol bock 

poi chiamato funzione bindNext come segue:

window.onload = function() { 
     bindNext(); 
    }