2016-11-03 2 views
2

AutoCompleteTextField는 TextField에서 백 스페이스를 시작할 때까지 의도 한대로 작동하는 것 같습니다. 차이점이 무엇인지 모르겠지만 "123 M"과 같은 것을 입력하면 "123 M"으로 시작하는 값을 얻습니다. 백 스페이스를 사용하여 필드에 "123"을 남기는 M을 삭제하면 목록이 변경되지만 목록의 맨 위로 스크롤되지는 않습니다.AutoCompleteTextField 목록이 항상 맨 위로 스크롤되지는 않습니까?

시뮬레이터에서 모든 것이 잘 작동하며 내 iPhone에서 디버그 빌드를 실행할 때이 문제가 발생합니다.

편집 : 그래서 이것은 백 스페이스 할 때 일어나는 것처럼 보이지 않습니다. 이 이미지는 키로 주소 키를 입력 할 때의 결과를 보여줍니다. 목록을 볼 수 없거나 잘리는 그림에서는 목록을 아래로 드래그하여 올바르게 표시 할 수 있습니다. 나는 안드로이드 장치에서 이것을 시도하지 않았습니다.

EDIT2 :

public class CodenameOneTest { 

    private Form current; 
    private Resources theme; 
    private WaitingClass w; 
    private String[] properties = {"1 MAIN STREET", "123 E MAIN STREET", "12 EASTER ROAD", "24 MAIN STREET"}; 

    public void init(Object context) { 
    theme = UIManager.initFirstTheme("/theme"); 

    // Enable Toolbar on all Forms by default 
    Toolbar.setGlobalToolbar(true); 
    } 

    public void start() { 
    if(current != null) { 
     current.show(); 
     return; 
    } 
    Form form = new Form("AutoCompleteTextField"); 
    form.setLayout(new BorderLayout()); 

    final DefaultListModel<String> options = new DefaultListModel<>(); 
    AutoCompleteTextField ac = new AutoCompleteTextField(options) { 
     protected boolean filter(String text) { 
     if(text.length() == 0) { 
      options.removeAll(); 
      return false; 
     } 

     String[] l = searchLocations(text); 
     if(l == null || l.length == 0) { 
      return false; 
     } 

     options.removeAll(); 
     for(String s : l) { 
      options.addItem(s); 
     } 
     return true; 
     }; 
    }; 
    Container container = new Container(BoxLayout.y()); 
    container.setScrollableY(true); // If you comment this out then the field works fine 
    container.add(ac); 

    form.addComponent(BorderLayout.CENTER, container); 
    form.show(); 
    } 

    String[] searchLocations(String text) { 
    try { 
     if(text.length() > 0) { 
     if(w != null) { 
      w.actionPerformed(null); 
     } 
     w = new WaitingClass(); 
     String[] properties = getProperties(text); 
     if(Display.getInstance().isEdt()) { 
      Display.getInstance().invokeAndBlock(w); 
     } 
     else { 
      w.run(); 
     } 
     return properties; 
     } 
    } 
    catch(Exception e) { 
     Log.e(e); 
    } 
    return null; 
    } 

    private String[] getProperties(String text) { 
    List<String> returnList = new ArrayList<>(); 

    List<String> propertyList = Arrays.asList(properties); 
    for(String property : propertyList) { 
     if(property.startsWith(text)) { 
     returnList.add(property); 
     } 
    } 
    w.actionPerformed(null); 
    return returnList.toArray(new String[returnList.size()]); 
    } 

    class WaitingClass implements Runnable, ActionListener<ActionEvent> { 
    private boolean finishedWaiting; 

    public void run() { 
     while(!finishedWaiting) { 
     try { 
      Thread.sleep(30); 
     } 
     catch(InterruptedException ex) { 
      ex.printStackTrace(); 
     } 
     } 
    } 

    public void actionPerformed(ActionEvent e) { 
     finishedWaiting = true; 
     return; 
    } 
    } 

    public void stop() { 
    current = Display.getInstance().getCurrent(); 
    if(current instanceof Dialog) { 
     ((Dialog)current).dispose(); 
     current = Display.getInstance().getCurrent(); 
    } 
    } 

    public void destroy() { 
    } 

} 

enter image description here

+0

Android/다른 기기에서 제대로 작동합니까? 어떻게 보이는지 알 수있는 스크린 샷을 제공 할 수 있습니까? –

+0

@ShaiAlmog 스크린 샷을 추가했습니다! – Tommo

+0

나는 스티브에게 이것을 시도하고 재현하도록 요청했는데 우리는 할 수 없었다. 문제를 재현하는 테스트 케이스를 게시 할 수 있습니까? –

답변

0

내가 아이폰 4S에이 코드를 사용 :

public void start() { 
    if(current != null){ 
     current.show(); 
     return; 
    } 
    Form hi = new Form("AutoComplete", new BorderLayout()); 
    if(apiKey == null) { 
     hi.add(new SpanLabel("This demo requires a valid google API key to be set in the constant apiKey, " 
       + "you can get this key for the webservice (not the native key) by following the instructions here: " 
       + "https://developers.google.com/places/web-service/get-api-key")); 
     hi.getToolbar().addCommandToRightBar("Get Key", null, e -> Display.getInstance().execute("https://developers.google.com/places/web-service/get-api-key")); 
     hi.show(); 
     return; 
    } 
    Container box = new Container(new BoxLayout(BoxLayout.Y_AXIS)); 
    box.setScrollableY(true); 
    for(int iter = 0 ; iter < 30 ; iter++) { 
     box.add(createAutoComplete()); 
    } 
    hi.add(BorderLayout.CENTER, box); 
    hi.show(); 
} 

private AutoCompleteTextField createAutoComplete() { 
    final DefaultListModel<String> options = new DefaultListModel<>(); 
    AutoCompleteTextField ac = new AutoCompleteTextField(options) { 
     @Override 
     protected boolean filter(String text) { 
      if(text.length() == 0) { 
       return false; 
      } 
      String[] l = searchLocations(text); 
      if(l == null || l.length == 0) { 
       return false; 
      } 

      options.removeAll(); 
      for(String s : l) { 
       options.addItem(s); 
      } 
      return true; 
     } 

    }; 
    ac.setMinimumElementsShownInPopup(5); 
    return ac; 
} 

String[] searchLocations(String text) {   
    try { 
     if(text.length() > 0) { 
      ConnectionRequest r = new ConnectionRequest(); 
      r.setPost(false); 
      r.setUrl("https://maps.googleapis.com/maps/api/place/autocomplete/json"); 
      r.addArgument("key", apiKey); 
      r.addArgument("input", text); 
      NetworkManager.getInstance().addToQueueAndWait(r); 
      Map<String,Object> result = new JSONParser().parseJSON(new InputStreamReader(new ByteArrayInputStream(r.getResponseData()), "UTF-8")); 
      String[] res = Result.fromContent(result).getAsStringArray("//description"); 
      return res; 
     } 
    } catch(Exception err) { 
     Log.e(err); 
    } 
    return null; 
} 

난 당신이 설명하는 문제를이 문제 enter image description here하지만를 만들 수 있었다.