사용자 정의 배열 어댑터를 기반으로 작성된 ListView에 필터를 구현했습니다. 이 목록에는 유명인의 이름과 그 유명 인사의 사진이 표시됩니다.사용자 정의 배열 어댑터 (안드로이드)로 ListView 필터링
public class Celebrities extends ListActivity {
private EditText filterText = null;
ArrayAdapter<CelebrityEntry> adapter = null;
private TextWatcher filterTextWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
adapter.getFilter().filter(s);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_celebrity);
//disables the up button
getActionBar().setDisplayHomeAsUpEnabled(true);
filterText = (EditText) findViewById(R.id.search_box);
filterText.addTextChangedListener(filterTextWatcher);
adapter = new CelebrityEntryAdapter(this, getModel());
setListAdapter(adapter);
}
그리고 CelebrityEntry.java에서 toString()
방법을 무시했습니다
public final class CelebrityEntry {
private String name;
private int pic;
public CelebrityEntry(String name, int pic) {
this.name = name;
this.pic = pic;
}
/**
* @return name of celebrity
*/
public String getName() {
return name;
}
/**
* override the toString function so filter will work
*/
public String toString() {
return name;
}
/**
* @return picture of celebrity
*/
public int getPic() {
return pic;
}
}
그러나, 내가 응용 프로그램을 부팅 및 필터링을 시작할 때, 각 목록 항목이 적절한있다을 사진이 포함되어 있지만 이름은 원래 목록에 불과하며 연예인 몇 명이 실제로 필터를 수행했는지 잘립니다. Kirsten Dunst가 목록의 첫 번째 항목이고 Adam Savage가 두 번째 항목이라고합니다. Adam Savage를 필터링하면 사진이 나옵니다.하지만이 두 가지 정보가 단일 개체의 요소 임에도 불구하고 Kirsten Dunst은 여전히 이름을 말합니다.
분명히 이것은 바람직한 결과가 아닙니다. 생각?
어댑터를 포함 할 수 있습니까? – eski
어댑터가 문제가되었습니다. 오늘 저녁에 그걸 알아 냈어. 감사! –