use of com.rongseal.pinyin.SideBar 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) {
}
});
}
use of com.rongseal.pinyin.SideBar in project SeaStar by 13120241790.
the class StartDiscussionActivity method initViews.
private void initViews() {
mLeftBtn = getBtn_left();
mLeftBtn.setText(R.string.start_disc_chat);
mRightBtn = getBtn_right();
mRightBtn.setVisibility(View.VISIBLE);
mRightBtn.setText(R.string.start_chat);
mRightBtn.setOnClickListener(this);
//实例化汉字转拼音类
characterParser = CharacterParser.getInstance();
pinyinComparator = PinyinComparator.getInstance();
//自动搜索
mAboutSerrch = (ClearWriteEditText) this.findViewById(R.id.dis_filter_edit);
//好友列表
mListView = (ListView) this.findViewById(R.id.dis_friendlistview);
//右侧好友指示 bar
mSidBar = (SideBar) this.findViewById(R.id.dis_sidrbar);
//中间提示的字母
dialog = (TextView) this.findViewById(R.id.dis_dialog);
show_no_friends = (TextView) this.findViewById(R.id.dis_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);
}
}
});
if (SourceDateList.size() == 0) {
//背景提示没有好友
show_no_friends.setVisibility(View.VISIBLE);
}
if (SourceDateList != null)
SourceDateList = filledData(SourceDateList);
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 StartDiscussionAdapter(StartDiscussionActivity.this, SourceDateList);
mListView.setAdapter(adapter);
//根据输入框输入值的改变来过滤搜索 顶部实时搜索
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