您必須將addTextChangedListener
加上TextWatcher
。
Boolean[] isPresent;
ed = (EditText) findViewById(R.id.editText1);
ed.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
textLength = ed.getText().length();
list.clear();
isPresent = initIsPresentArray();
for (int i = 0; i < tempList.length; i++) {
for (int j = 0; j < (tempList[i].length() - (textLength - 1)); j++) {
if (textLength <= tempList[i].length()) {
if (isPresent[i] == false) {
if (ed.getText()
.toString()
.equalsIgnoreCase(
(String) tempList[i]
.subSequence(
j,
(j + textLength)))) {
list.add(tempCaseList.get(i));
isPresent[i] = true;
}
}
}
}
if (list.size() == 0) {
error.setText(getResources().getString(R.string.notFound));
} else {
error.setText("");
}
lv.setAdapter(new CustomAdapter(History.this, list));
}
}
});
而且方法initIsPresentArray()
public Boolean[] initIsPresentArray() {
Boolean[] isPresent = new Boolean[tempCaseList.size()];
for (int i = 0; i < isPresent.length; i++) {
isPresent[i] = false;
}
return isPresent;
}
正如你可能會看到,我不做直接包含的信息ArrayList
操作,但我在複製這個ArrayList
到一個臨時ArrayList
,使用這種方法
public ArrayList<Case> createTempList(ArrayList<Case> listOfCases) {
ArrayList<Case> temporaryList = new ArrayList<Case>();
for (Case c : listOfCases) {
temporaryList.add(c);
}
return temporaryList;
}
只要添加評論,如果有什麼東西是未完成的!
那肯定會變得很快。我會試一試,讓你知道它是怎麼回事! – VicVu
是的。但它對我來說非常合適 –
在上週遇到了幾個障礙。我會回到這裏,讓我知道如果它能儘快工作,對不起! – VicVu