android, AutoCompleteTextView 때문에 Filterable 을 적용한 경우 example. |
AutoCompleteTextView 때문에 Filterable 을 적용한 경우, 어떤 sequence 로 함수들이 불릴까?
1. getFilter ( 1회만 불림 )
2. 글자 하나당 performFiltering, publishResults 가 순차적으로 불림.
3. publishResults 에서 notifyDataSetChanged 가 불리면getCount 를 부르면서 일반적인 list drawing 이 진행됨.
private static class AutoCompleteAdapter extends BaseAdapter implements Filterable{
private List<GeoInfo> mGeoInfos;
public void setGeoInfos( List<GeoInfo> geoInfos ){
mGeoInfos = geoInfos;
notifyDataSetChanged();
}
public void clear() {
if ( !Utils.isEmptyList( mGeoInfos ) )
mGeoInfos.clear();
}
@Override
public int getCount() {
if ( Utils.isEmptyList( mGeoInfos ) ) return 0;
return mGeoInfos.size();
}
@Override
public GeoInfo getItem(int position) {
return mGeoInfos.get( position );
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if ( convertView == null )
convertView = ViewUtils.getInflatedView( parent.getContext(), android.R.layout.simple_list_item_2 );
GeoInfo geoInfo = mGeoInfos.get( position );
((TextView)convertView.findViewById( android.R.id.text1 )).setText( geoInfo.getShortName() );
((TextView)convertView.findViewById( android.R.id.text2 )).setText( geoInfo.getLongName() );
return convertView;
}
@Override
public Filter getFilter() {
return new Filter(){
@Override
protected FilterResults performFiltering(CharSequence constraint) {
if ( !Utils.isAssembledKorean( constraint.toString(), ' ' ) ) return null;
FilterResults filterResults = new FilterResults();
if ( !Utils.isEmptyList( mGeoInfos ) ){
filterResults.values = mGeoInfos;
filterResults.count = mGeoInfos.size();
}
return filterResults;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
if ( results == null || results.count == 0 )
notifyDataSetInvalidated();
else
notifyDataSetChanged();
}
};
}
}
'프로그래밍 놀이터 > 안드로이드, Java' 카테고리의 다른 글
[android] how to input xml percentage sign (0) | 2014.04.09 |
---|---|
Android Transition Animation (TransitionManager, Transition, Scene) Tutorial (0) | 2014.04.08 |
[android] compat version mapfragment xml example. (0) | 2014.04.07 |
[android] Fake Message로 GCM 수신 테스트 하기. ( simulation ) (0) | 2014.04.07 |
[android] Launch UX Improvement. (0) | 2014.04.04 |
댓글