use of com.rongseal.adapter.FriendAdapter in project SeaStar by 13120241790.
the class FriendsFragment method initView.
private void initView() {
//实例化汉字转拼音类
characterParser = CharacterParser.getInstance();
pinyinComparator = PinyinComparator.getInstance();
mAboutSerrch = (ClearWriteEditText) mView.findViewById(R.id.filter_edit);
mListView = (ListView) mView.findViewById(R.id.friendlistview);
mSidBar = (SideBar) mView.findViewById(R.id.sidrbar);
dialog = (TextView) mView.findViewById(R.id.dialog);
show_no_friends = (TextView) mView.findViewById(R.id.show_no_friends);
mSidBar.setTextView(dialog);
//设置右侧触摸监听
mSidBar.setOnTouchingLetterChangedListener(new SideBar.OnTouchingLetterChangedListener() {
@Override
public void onTouchingLetterChanged(String s) {
//该字母首次出现的位置
int position = adapter.getPositionForSection(s.charAt(0));
if (position != -1) {
mListView.setSelection(position);
}
}
});
//-------------- 获取好友列表数据 ---------------
friendDao = DBManager.getInstance(getActivity()).getDaoSession().getFriendDao();
QueryBuilder<com.rongseal.db.com.rongseal.database.Friend> qb = friendDao.queryBuilder();
if (qb.list().size() > 0 && qb.list() != null) {
for (int i = 0; i < qb.list().size(); i++) {
com.rongseal.db.com.rongseal.database.Friend bean = qb.list().get(i);
mSourceDateList.add(new Friend(bean.getUserId(), bean.getName(), bean.getPortraitUri()));
}
} else {
//TODO 是否需要网络再次拉取? login 已经拉取存数据库
NLog.e("database", "friend database is null");
}
//过滤数据对象为友字母字段
SourceDateList = filledData(mSourceDateList);
if (SourceDateList.size() > 0) {
show_no_friends.setVisibility(View.GONE);
}
for (int i = 0; i < mSourceDateList.size(); i++) {
SourceDateList.get(i).setUserId(mSourceDateList.get(i).getUserId());
SourceDateList.get(i).setName(mSourceDateList.get(i).getName());
SourceDateList.get(i).setUri(mSourceDateList.get(i).getUri());
}
mSourceDateList = null;
// 根据a-z进行排序源数据
Collections.sort(SourceDateList, pinyinComparator);
adapter = new FriendAdapter(getActivity(), SourceDateList);
mListView.setAdapter(adapter);
mListView.setOnItemLongClickListener(this);
mListView.setOnItemClickListener(this);
//根据输入框输入值的改变来过滤搜索 顶部实时搜索
mAboutSerrch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
//当输入框里面的值为空,更新为原来的列表,否则为过滤数据列表
filterData(s.toString());
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
Aggregations