我有一个字符串数组,用于在微调器中显示。现在我的需要是
当用户在编辑文本中提供输入时,必须根据编辑文本值对数组进行排序,并且必须在微调器中显示它。我无法完全理解逻辑。
我试过这样,
String[] a1 = { "Android", "Apple", "Andrew", "Ball" }, a2 = null;
EditText mn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mn = (EditText) findViewById(R.id.plus);
a2 = a1;
mn.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
Arrays.sort(a1);
doCall();
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
}
@Override
public void afterTextChanged(Editable arg0) {
}
});
}
protected void doCall() {
for (int i = 0; i < a1.length; i++) {
String s = a1[i];
for (int j = 0; j < mn.getText().toString().length(); j++) {
if (Character.toLowerCase(s.charAt(j)) == Character
.toLowerCase(mn.getText().toString().charAt(j))) {
if (j == mn.getText().toString().length() - 1) {
String temp = a1[0];
a1[0] = a2[i];
a1[i] = temp;
} else {
continue;
}
} else {
break;
}
}
}
}
如果我给“a”意味着我得到“Andrew,Ball,Apple,Android”但我需要展示的是“Andrew,Android,Apple,Ball”我怎样才能做到这一点。提前致谢,