예제 #1
0
 public void startDownloadListFaculties(ArrayAdapter<String> arrayAdapter) {
   if (!m_activeApp) {
     StaticStorage.m_listFaculties.clear();
     Thread thread;
     m_activeApp = true;
     m_download_finished = false;
     textView.setCompletionHint(getActivity().getString(R.string.placeholder_downloading));
     ServerGetFaculties serverGetFaclts =
         new ServerGetFaculties((ArrayAdapter<String>) textView.getAdapter());
     serverGetFaclts.execute();
     m_activeApp = true;
     thread =
         new Thread() {
           public void run() {
             try {
               while (!m_download_finished) {
                 Thread.sleep(200);
                 if (!textView.getAdapter().isEmpty()) {
                   textView.setCompletionHint("");
                   m_download_finished = true;
                 }
               } // while
             } catch (Exception ex) {
             }
           }
         };
     thread.start();
   }
 }
예제 #2
0
 /**
  * 初始化AutoCompleteTextView,最多显示5项提示,使 AutoCompleteTextView在一开始获得焦点时自动提示
  *
  * @param field 保存在sharedPreference中的字段名
  * @param auto 要操作的AutoCompleteTextView
  */
 private void initAutoComplete(String field, AutoCompleteTextView auto) {
   String[] hisArrays = getFieldHistInputData(field);
   if (hisArrays != null) {
     ArrayAdapter<String> adapter =
         new ArrayAdapter<String>(
             getActivity(), android.R.layout.simple_dropdown_item_1line, hisArrays);
     // 只保留最近的50条的记录
     if (hisArrays.length > 100) {
       String[] newArrays = new String[100];
       System.arraycopy(hisArrays, 0, newArrays, 0, 100);
       adapter =
           new ArrayAdapter<String>(
               getActivity(), android.R.layout.simple_dropdown_item_1line, newArrays);
     }
     auto.setAdapter(adapter);
     // auto.setDropDownHeight(350);
     auto.setThreshold(1);
     auto.setCompletionHint("历史记录");
     auto.setOnFocusChangeListener(
         new OnFocusChangeListener() {
           @Override
           public void onFocusChange(View v, boolean hasFocus) {
             AutoCompleteTextView view = (AutoCompleteTextView) v;
             if (hasFocus) {
               view.showDropDown();
             }
           }
         });
   }
 }