我如何从中间自动填充编辑文本?
How can i auto-fill an edit text from it's mid?
我正在为 android.In 开发一个联系人管理器项目,我想在用户注册时自动填写字段中的电子邮件地址结尾部分。
例如,当用户键入他或她的用户名时,它应该自动给出@gmail.com 或@outlook.com 等的建议。
嗯,这是我代码的一小部分
String[] maindb = {"@gmail.com", "@rediffmail.com", "@hotmail.com", "@outlook.com"};
mail = (AutoCompleteTextView) findViewById(R.id.A1_edt_mail);
ArrayAdapter<String> adpt = new ArrayAdapter<String>(this, R.layout.support_simple_spinner_dropdown_item, maindb);
mail.setAdapter(adpt);
好吧,我得到了这样的输出
但我希望当用户输入 his/her 用户名时,应该会出现此建议,但不会出现。
嗯,我的问题不是 android how an EditText work as AutoComplete 的重复问题
这个 question.My 问题与此不同。
提前致谢。
我建议您在设置适配器之前将电子邮件中的文本附加到 maindb 中的每个字符串 --> 使用 TextWatcher 检测邮件视图的更改。
编辑
可能这就是您要找的东西
final ArrayList<String> maindb = new ArrayList<>();
maindb.add("@gmail.com");
maindb.add("@rediffmail.com");
maindb.add("@hotmail.com");
maindb.add("@outlook.com");
final ArrayList<String> compare = new ArrayList<>();
final ArrayAdapter<String> adpt = new ArrayAdapter<String>(MainActivity.this, R.layout.support_simple_spinner_dropdown_item, compare);
Word.setAdapter(adpt);
Word.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (s.length() >= 0)
if (!s.toString().contains("@")) {
compare.clear();
for (String aMaindb : maindb) {
aMaindb = s + aMaindb;
compare.add(aMaindb);
}
adpt.clear();
adpt.addAll(compare);
}
}
});
希望这会有所帮助
我正在为 android.In 开发一个联系人管理器项目,我想在用户注册时自动填写字段中的电子邮件地址结尾部分。 例如,当用户键入他或她的用户名时,它应该自动给出@gmail.com 或@outlook.com 等的建议。
嗯,这是我代码的一小部分
String[] maindb = {"@gmail.com", "@rediffmail.com", "@hotmail.com", "@outlook.com"};
mail = (AutoCompleteTextView) findViewById(R.id.A1_edt_mail);
ArrayAdapter<String> adpt = new ArrayAdapter<String>(this, R.layout.support_simple_spinner_dropdown_item, maindb);
mail.setAdapter(adpt);
好吧,我得到了这样的输出
但我希望当用户输入 his/her 用户名时,应该会出现此建议,但不会出现。
嗯,我的问题不是 android how an EditText work as AutoComplete 的重复问题 这个 question.My 问题与此不同。
提前致谢。
我建议您在设置适配器之前将电子邮件中的文本附加到 maindb 中的每个字符串 --> 使用 TextWatcher 检测邮件视图的更改。
编辑
可能这就是您要找的东西
final ArrayList<String> maindb = new ArrayList<>();
maindb.add("@gmail.com");
maindb.add("@rediffmail.com");
maindb.add("@hotmail.com");
maindb.add("@outlook.com");
final ArrayList<String> compare = new ArrayList<>();
final ArrayAdapter<String> adpt = new ArrayAdapter<String>(MainActivity.this, R.layout.support_simple_spinner_dropdown_item, compare);
Word.setAdapter(adpt);
Word.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (s.length() >= 0)
if (!s.toString().contains("@")) {
compare.clear();
for (String aMaindb : maindb) {
aMaindb = s + aMaindb;
compare.add(aMaindb);
}
adpt.clear();
adpt.addAll(compare);
}
}
});
希望这会有所帮助