private ArrayList <HashMap<String, Object>> availableFriends;
public ListAdapter adapter = null;
friendsearch = (EditText)findViewById(R.id.friendsearch);
friendsearch.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
FriendsActivity.this.adapter.getFilter().filter(cs);
In the above line i am getting the error ,here what i am trying to do is search in a custom list view (list view with image and name)
}
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
below code shows you how i am getting the list data and how i am displaying the list data.
if it required please watch it other wise leave it.
public List<Friend> getFriendsList(){
String accessToken = null;
DatabaseHelper helper = new DatabaseHelper(getApplicationContext());
DatabaseUtility dao = new DatabaseUtility(helper);
try {
accessToken = dao.getAccessToken();
} catch (Exception e1) {
handler.sendEmptyMessage(1);
return null;
}
if(accessToken == null || accessToken.length() == 0){
handler.sendEmptyMessage(1);
return null;
}
Map<String , String> params = new HashMap<String,String>();
params.put(Constants.ACCESS_TOKEN_PARAM, accessToken);
List<Friend> friendsList = null;
try {
friendsList = Utils.getFriendsList(params,this);
} catch (NullPointerException e) {
handler.sendEmptyMessage(12);
return null;
} catch (JSONException e) {
//handler.sendEmptyMessage(11);
return null;
}
return friendsList;
}
public void displayFriends(List<Friend> friendList){
List<Friend> friendsList = friendList;
availableFriends = new ArrayList<HashMap<String,Object>>();
HashMap<String, Object> friendData = null;
Friend friend = null;
try{
for(int i = 0 ; i < friendsList.size() ; i++){
friend = friendsList.get(i);
friendData = new HashMap<String, Object>();
friendData.put(FRIENDS_NAME_KEY, friend.getFriendName());
friendData.put(IS_IMAGE_KEY, friend.getIsImage());
friendData.put(IDKEY, friend.getFriendID());
availableFriends.add(friendData);
}
adapter = new ListAdapter(availableFriends,FriendsActivity.this);
listView.setAdapter(adapter);
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
ListAdapterdoes not implement theFilterableinterface. However, some adapters, such asArrayAdapterandSimpleAdapterdo. This means you should consider switching your adapter to something that implements the interface or make your own custom Adapter and implement it there.Also, based on the code above, you set your
adapterto be null and you don’t initialize it (I don’t see a call todisplayFriends(). You should also look into that to make sure your initializations are proper (after choosing a more appropriate adapter of course).