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);
在上面的行中我得到了错误,这里我想做的是在自定义列表视图中搜索(带有图像和名称的列表视图)}
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
}
});
下面的代码向您展示了我如何获取列表数据以及如何显示列表数据。如果需要,请注意它,否则请离开它。
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);