为 Android AutoCompleteTextView 从数据库中检索 JSON 数据的最佳方法是什么?

What is the best way to retrieve JSON data from database for Android AutoCompleteTextView?

我想为 Android 开发一个动态 AutoCompleteTextView,其中填充了从 MySQL 数据库检索到的 JSON 数据。基本上这不是一项艰巨的任务,但我在哪里面临问题?我受到 jQuery Autocomplete 选项的启发,该选项在输入字母后动态获取数据。但是 android AutoCompleteTextView 预填充了所有 JSON 数据。
我正在尝试从数百万很难存储的数据中进行查询。有没有办法动态搜索数据库中的输入?

例如:

Such as if user input "a" then it will retrieve the best result for "a". Then if user type "ab" it will be refreshed and populated with new results from database.

谢谢

我将只为您的任务提供一个总体概述,看起来像这样,

public List<String> suggest; //List of suggestions

 autoComplete.addTextChangedListener(new TextWatcher(){

        public void afterTextChanged(Editable editable) {
            // TODO Auto-generated method stub

        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub

        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            String newText = s.toString();
            new getJson().execute(newText);
        }

    });

getJson AsyncTask -> 用于从服务器检索新值

 class getJson extends AsyncTask<String,String,String>{

    @Override
    protected String doInBackground(String... key) {
        String newText = key[0];
        newText = newText.trim();
        newText = newText.replace(" ", "+");
        try{
            //Codes to retrieve the data for suggestions
            suggest = new ArrayList<String>();
            JSONArray jArray = new JSONArray(data);
            for(loop the array){
            String SuggestKey = //retrieve values by iterating;
            suggest.add(SuggestKey);
            }

        }catch(Exception e){
            Log.w("Error", e.getMessage());
        }

       //Populate suggestions

        runOnUiThread(new Runnable(){
            public void run(){
                 aAdapter = new ArrayAdapter<String>(getApplicationContext(),R.layout.item,suggest);
                 autoComplete.setAdapter(aAdapter);
                 aAdapter.notifyDataSetChanged();
            }
        });

        return null;
    }

有关详细信息,请参阅 here