Adapter
===============
public class Adpt_ChartingTemplate extends BaseAdapter implements Filterable {
private Context context;
private LayoutInflater mInflater;
private SHSact_Main shSact_main;
private ArrayList<SHScl_ChartingTemplates> arrayListChartingTemplateMain=new ArrayList<SHScl_ChartingTemplates>() ;
private ArrayList<SHScl_ChartingTemplates> arrayListChartingTemplateFilter=new ArrayList<SHScl_ChartingTemplates>() ;
public Adpt_ChartingTemplate(SHSact_Main shSact_main, ArrayList<SHScl_ChartingTemplates> arrayList_ChartingTemplate) {
this.context = shSact_main.getApplicationContext();
this.shSact_main = shSact_main;
mInflater = LayoutInflater.from(context);
this.arrayListChartingTemplateMain = arrayList_ChartingTemplate;
this.arrayListChartingTemplateFilter = arrayList_ChartingTemplate;
}
@Override public int getCount() {
return arrayListChartingTemplateFilter.size();
}
@Override public Object getItem(int position) {
return arrayListChartingTemplateFilter.get(position);
}
@Override public long getItemId(int position) {
return position;
}
@Override public View getView(final int position, View convertView, ViewGroup parent) {
final ListContent holder;
View v = convertView;
if (v == null) {
v = View.inflate(context, R.layout.listitem_charting_template, null);
holder = new ListContent();
holder.txt_name = (TextView) v.findViewById(R.id.listitem_charting_template_txt_name);
v.setTag(holder);
} else {
holder = (ListContent) v.getTag();
}
holder.txt_name.setText(arrayListChartingTemplateFilter.get(position).template_name);
return v;
}
@Override public Filter getFilter() {
return new ItemFilter();
}
private class ListContent {
TextView txt_name,txt_specialization;
}
private class ItemFilter extends Filter {
@Override protected FilterResults performFiltering(CharSequence constraint) {
String filterString = constraint.toString().toLowerCase();
FilterResults results = new FilterResults();
final List<SHScl_ChartingTemplates> list = arrayListChartingTemplateMain;
int count = list.size();
final ArrayList<SHScl_ChartingTemplates> nlist = new ArrayList<SHScl_ChartingTemplates>(count);
String filterableString;
for (int i = 0; i < count; i++) {
filterableString = list.get(i).template_name;
if (filterableString.toLowerCase().contains(filterString)) {
nlist.add(list.get(i));
}
}
results.values = nlist;
results.count = nlist.size();
return results;
}
@SuppressWarnings("unchecked")
@Override protected void publishResults(CharSequence constraint, FilterResults results) {
arrayListChartingTemplateFilter = (ArrayList<SHScl_ChartingTemplates>) results.values;
notifyDataSetChanged();
}
}
}
EditText
========================
edt_searchByName.addTextChangedListener(new TextWatcher() {
@Override public void onTextChanged(CharSequence s, int start, int before, int count) {
adpt_ChartingTemplate.getFilter().filter(s.toString());
}
@Override public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override public void afterTextChanged(Editable s) {
}
});
// Same like with onItemSelectedLitner method of Spinner you can do.
No comments:
Post a Comment