Java AutoCompleteTextView使用json查找word

Java AutoCompleteTextView使用json查找word,java,android,Java,Android,我的资产文件夹中有一个all.json文件,我希望在输入文本时它能显示在AutoCompleteTextView中。 这是我的json文件示例: {“单词”:合図","含义:“符号,信号”,“平假名”:あいず","罗马书“:“艾祖”,“等级”:3} 我希望无论我输入英语还是日语,它都会自动显示选择。 如何设置阵列适配器? 有人能帮我吗? 谢谢。 这是我的代码: public class test extends AppCompatActivity { AutoCompleteTextVi

我的资产文件夹中有一个all.json文件,我希望在输入文本时它能显示在AutoCompleteTextView中。
这是我的json文件示例:
{“单词”:合図","含义:“符号,信号”,“平假名”:あいず","罗马书“:“艾祖”,“等级”:3}
我希望无论我输入英语还是日语,它都会自动显示选择。
如何设置阵列适配器?
有人能帮我吗?
谢谢。
这是我的代码:

public class test extends AppCompatActivity {
    AutoCompleteTextView autotxt;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        String result = dbsearchall.executeQuery("n5.json");
        autotxt = (AutoCompleteTextView)findViewById(R.id.autotxt);

        try {
             JSONObject obj = new JSONObject(loadJSONFromAsset());
             JSONArray countries=obj.getJSONArray("countries");
             ArrayAdapter<String> adapter
                = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line,
                countries); //宣告 Adapter
            autotxt.setAdapter(adapter);  
            autotxt.setThreshold(1);  
            autotxt.setDropDownWidth(800);  
            autotxt.setDropDownHeight(400); 
        } catch (JSONException e) {

        }

    }
        public String loadJSONFromAsset() {
        String json = null;
        try {
            InputStream is = getAssets().open("all.json");
            int size = is.available();
            byte[] buffer = new byte[size];
            is.read(buffer);
            is.close();
            json = new String(buffer, "UTF-8");

        } catch (IOException ex) {}
        
        return json;

    }
     
}
公共类测试扩展了AppCompatActivity{
自动完成文本视图自动文本;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_测试);
String result=dbsearchall.executeQuery(“n5.json”);
autotext=(AutoCompleteTextView)findviewbyd(R.id.autotext);
试一试{
JSONObject obj=新的JSONObject(loadJSONFromAsset());
JSONArray国家=对象getJSONArray(“国家”);
阵列适配器
=新阵列适配器(此,
android.R.layout.simple\u下拉列表\u项目\u 1行,
国家)//宣告 适配器
autotext.setAdapter(适配器);
自动文本设置阈值(1);
AutoText.setDropDownWidth(800);
AutoText.setDropDownHeight(400);
}捕获(JSONException e){
}
}
公共字符串loadJSONFromAsset(){
字符串json=null;
试一试{
InputStream=getAssets().open(“all.json”);
int size=is.available();
字节[]缓冲区=新字节[大小];
is.read(缓冲区);
is.close();
json=新字符串(缓冲区,“UTF-8”);
}catch(IOException ex){}
返回json;
}
}

我认为这不是最有效的方法。查看
Trie
数据结构。这可能会有帮助。梅兰B好的,我会试试我的坏兄弟。你的解决方案看起来不错,我没有完全阅读你的代码。但我对你的问题没有答案。