android 實現類似qq未讀訊息點選迴圈顯示

laughingQing發表於2016-12-20
public void jumpUnread(boolean cycle) {
List<ContactLogModel> dataList = adapter.getContactLogModelList();
int dataSize = dataList.size();

int position = 0;
if (cycle) {
position = 0;
} else {
position = ListView().getFirstVisiblePosition();
}
ConfigInfo.logDebug(TAG, "1 .......... get view first item pos:" + position);

for (int i = position; i < dataSize; i++) {
position++;
ConfigInfo.logDebug(TAG, "2 ..........mode detail" + dataList.get(i).getUname() + ".....i" + i);
if (dataList.get(i).getUnread() > 0) { // 未讀處理
ListView.setSelection(position);
ConfigInfo.logDebug(TAG, "4 .............position" + position);
return;
}
}

if (position > 0) {
jumpUnread(true);
}
}

public void jumpUnread() {

List<ContactLogModel> dataList = adapter.getContactLogModelList();
int position = mPtrFrameLayout.getListView().getFirstVisiblePosition();
ConfigInfo.logDebug(TAG, "1 .......... get view first item pos:" + position);
for (int i = position; i < adapter.getCount(); i++) {
ConfigInfo.logDebug(TAG, "2 ..........mode detail" + dataList.get(i).getUname() + ".....i" + i);
if (dataList.get(i).getUnread() > 0) { // 未讀處理
if(isListViewReachBottomEdge(mPtrFrameLayout.getListView())){
reJumpUnread();
}else{
mPtrFrameLayout.getListView().setSelection(i + 1);
}
ConfigInfo.logDebug(TAG, "4 .............position" + position);
return;
}
}
reJumpUnread();
}


public void reJumpUnread() {
for (int i = 0; i < adapter.getCount(); i++) {
if (adapter.getItem(i).getUnread() > 0) { // 未讀處理
mPtrFrameLayout.getListView().setSelection(i + 1);
return;
}
}
}


public boolean isListViewReachBottomEdge(final AbsListView listView) {
boolean result = false;
if (listView.getLastVisiblePosition() == (listView.getCount() - 1)) {
final View bottomChildView = listView.getChildAt(listView.getLastVisiblePosition() - listView.getFirstVisiblePosition());
result = (listView.getHeight() >= bottomChildView.getBottom());
ConfigInfo.logDebug(TAG,"..............."+result);
};
return result;
}


相關文章