在输入后,Show最近如何在使用共享首选项的情况下进入编辑文本中的文本



我想要一个编辑文本,该文本最近显示了本文本,如稍后我何时在移动中输入其他文本(例如手机中的电话簿(,如果前3位数字或字母匹配,则显示建议,并显示该建议。不匹配IT不会显示建议。
谢谢。

        super.onCreate(savedInstanceState);
        setContentView(R.layout.onemore);
        srchButton = (Button) findViewById(R.id.search);
        editText_Acct_Id = (EditText) findViewById(R.id.acct_id);
        savednotes = getSharedPreferences("notes",MODE_PRIVATE);
        editText_Acct_Id.setText(savednotes.getString("tag", "Default Value"));

当我想将文本保存为建议

时,这是我的单击
srchButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(editText_Acct_Id.getText().length()>0){
                    makeTag(editText_Acct_Id.getText().toString());
                    ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(editText_Acct_Id.getWindowToken(),0);
                }

和我称之为

的方法
   private void makeTag(String tag){
        String or = savednotes.getString(tag, null);
        SharedPreferences.Editor preferencesEditor = savednotes.edit();
        preferencesEditor.putString("tag",tag); //change this line to this
        preferencesEditor.commit();
    }

首先转换您的Edittext-> autocompletetextview。还将共享首选项数据添加到字符串数组列表中。然后在使用以下代码之后,例如...

        String[] countries = getResources().getStringArray(R.array.list_of_countries_name);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,countries);
    mAutoCompleteTextView.setAdapter(adapter);
    mAutoCompleteTextView.setThreshold(1);

最新更新