Vote count:
0
can you please tell me how to make custom filter in android using bas adapter ? I make a simple demo of auto complete. I take array of string in which there is 2250 entries with Name and code like that example "Alexandra Palace-(AAP)", first name is given and the it code inside the bracket.my issue is I need to filter this using code not by name .In other word if i type anything in input field it filter with starting characters of element mean name I need to filter with code which is inside the bracket.
Code:
package com.firstgroup.global;
public class GlobalList {
public static String[] stationList={
"MNCRLWY-(LWY)",
"Lympstone Commando-(LYC)",
"Lydney-(LYD)",
"Lye-(LYE)",
"Lympstone Village-(LYM)",
"Lymington Pier-(LYP)",
"Lymington Town-(LYT)",
"Lazonby & Kirkoswald-(LZB)",
"Leeds, Whitehall (Bus)-(LZZ)",
"Macclesfield-(MAC)",
"Maghull-(MAG)",
"Maidenhead-(MAI)",
"Malden Manor-(MAL)",
"Manchester Piccadilly-(MAN)",
"Martins Heron-(MAO)",
"Margate-(MAR)",
"Manors-(MAS)",
"Matlock-(MAT)",
"Mauldeth Road-(MAU)",
"Mallow-(MAW)",
"Maxwell Park-(MAX)",
"Maybole-(MAY)",
"Millbrook (Hampshire)-(MBK)",
"Middlesbrough-(MBR)",
"Moulsecoomb-(MCB)",
"Metro Centre-(MCE)",
"March-(MCH)",
"Marne La Vallee-(MCK)",
"Morecambe-(MCM)",
"Machynlleth-(MCN)",
"Manchester Oxford Road-(MCO)",
"Manchester Victoria-(MCV)",
"Maidstone Barracks-(MDB)",
"Maidstone East-(MDE)",
"Midgham-(MDG)",
"Middlewood-(MDL)",
"Maiden Newton-(MDN)",
"Morden South-(MDS)",
"Maidstone West-(MDW)",
"MAERDY-(MDY)",
"Meols Cop-(MEC)",
"Meldreth-(MEL)",
"Menheniot-(MEN)",
"Meols-(MEO)",
"Meopham-(MEP)",
"Merthyr Tydfil-(MER)",
"Melton-(MES)",
"Merthyr Vale-(MEV)",
"Maesteg (Ewenny Road)-(MEW)",
"Mexborough-(MEX)",
"Merryton-(MEY)",
"Morfa Mawddach-(MFA)",
"Minffordd-(MFD)",
"Minffordd-(MFF)",
"Milford Haven-(MFH)",
"Mount Florida-(MFL)",
"Mansfield-(MFT)",
"Metheringham-(MGM)",
"Marston Green-(MGN)",
"Minehead-(MHD)",
"Merstham-(MHM)",
"Market Harborough-(MHR)",
"Meadowhall-(MHS)",
"Manchester Airport-(MIA)",
"Micheldever-(MIC)",
"Millfield (T & W Metro)-(MIF)",
"Mills Hill-(MIH)",
"Mitcham Junction-(MIJ)",
"Micklefield-(MIK)",
"Mill Hill Broadway-(MIL)",
"Moreton-in-Marsh-(MIM)",
"Milliken Park-(MIN)",
"Mirfield-(MIR)",
"Mistley-(MIS)",
"Milton Keynes Central-(MKC)",
"Melksham-(MKM)",
"Market Rasen-(MKR)",
"Marks Tey-(MKT)",
"Millbrook (Bedfordshire)-(MLB)",
"Mouldsworth-(MLD)",
"Milford (Surrey)-(MLF)",
"Mallaig-(MLG)",
"Mill Hill (Lancashire)-(MLH)",
"Millom-(MLM)",
"Milngavie-(MLN)",
"MILESPL-(MLP)",
"Milnrow-(MLR)",
"Melrose (Bus)-(MLS)",
"Malton-(MLT)",
"Marlow-(MLW)",
"Morley-(MLY)",
"Melton Mowbray-(MMO)",
"Markinch-(MNC)",
"Manea-(MNE)",
"Manningtree-(MNG)",
"Menston-(MNN)",
"Manor Park-(MNP)",
"Manor Road-(MNR)",
"MINZHBF-(MNZ)",
"Mobberley-(MOB)",
"Moorgate-(MOG)",
"Monifieth-(MON)",
};
}
when I type "lwy" it will not show "MNCRLWY-(LWY)", can you please tell how I will achieve this ?
here is my code..
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.select_station);
autocompleteView = (AutoCompleteTextView) findViewById(R.id.item_autoComplete);
STATION_LIST = new String[GlobalList.stationList.length
+ GlobalExtendStationList.stationList.length];
System.arraycopy(GlobalList.stationList, 0, STATION_LIST, 0,
GlobalList.stationList.length);
System.arraycopy(GlobalExtendStationList.stationList, 0,
STATION_LIST, GlobalList.stationList.length,
GlobalExtendStationList.stationList.length);
autosuggestAdapter = new CustomAutocompletAdapter(this,STATION_LIST);
autocompleteView.setAdapter(autosuggestAdapter);
customAutosuggestAdapter:
public class CustomAutocompletAdapter extends BaseAdapter implements Filterable{
String[] autolistArray;
private Context context;
public CustomAutocompletAdapter( Context context, String[] autolistArray){
this.autolistArray=autolistArray;
this.context = context;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View v = convertView;
if (v == null) {
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = mInflater.inflate(R.layout.custom_row_adapter, null);
}
final TextView stationNameAndCode = (TextView) v
.findViewById(R.id.item_selectStationName);
final String stationNameAndCodeValue = autolistArray[position];
stationNameAndCode.setText(stationNameAndCodeValue);
return v;
}
@Override
public Filter getFilter() {
// TODO Auto-generated method stub
Filter myFilter = new Filter() {
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint,
FilterResults results) {
System.out.println("Constraint " + constraint);
Log.d("-----------", "publishResults");
// has
}
@Override
protected FilterResults performFiltering(CharSequence constraint) {
Log.d("-----------", "performFiltering");
FilterResults results = new FilterResults(); // Holds the
// results of a
// filtering
// operation in
// values
/********
*
* If constraint(CharSequence that is received) is null returns
* the mOriginalValues(Original) values else does the Filtering
* and returns FilteredArrList(Filtered)
*
********/
Locale locale = Locale.getDefault();
constraint = (String) constraint
.toString().toLowerCase(locale);
if (constraint == null || constraint.length() == 0) {
// set the Original result to return
} else {
}
return results;
}
@Override
public CharSequence convertResultToString(Object resultValue) {
// TODO Auto-generated method stub
//convert object to string
Log.d("-----------", "convertResultToString");
return "";
}
};
return myFilter;
}
}
It is not showing no auto suggest. Could you please tell how I will achieve this? Mean filter functionality? I want to add filter method when I type in input field it filter from code not from name..
how to make custom filter in android using bas adapter?
Aucun commentaire:
Enregistrer un commentaire