Merge "Import translations. DO NOT MERGE"
diff --git a/src/com/android/contacts/editor/GroupMembershipView.java b/src/com/android/contacts/editor/GroupMembershipView.java
index cb66b73..d41991c 100644
--- a/src/com/android/contacts/editor/GroupMembershipView.java
+++ b/src/com/android/contacts/editor/GroupMembershipView.java
@@ -94,6 +94,9 @@
*/
private class GroupMembershipAdapter<T> extends ArrayAdapter<T> {
+ // The position of the group with the largest group ID
+ private int mNewestGroupPosition;
+
public GroupMembershipAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
}
@@ -130,6 +133,15 @@
return checkedTextView;
}
+
+ public int getNewestGroupPosition() {
+ return mNewestGroupPosition;
+ }
+
+ public void setNewestGroupPosition(int newestGroupPosition) {
+ mNewestGroupPosition = newestGroupPosition;
+ }
+
}
private RawContactDelta mState;
@@ -192,7 +204,7 @@
onClick(this); // This causes the popup to open.
if (mPopup != null) {
// Ensure that the newly created group is checked.
- int position = mAdapter.getCount() - 2;
+ final int position = mAdapter.getNewestGroupPosition();
ListView listView = mPopup.getListView();
if (listView != null && !listView.isItemChecked(position)) {
// Newly created group is not checked, so check it.
@@ -307,6 +319,8 @@
mAdapter = new GroupMembershipAdapter<GroupSelectionItem>(
getContext(), R.layout.group_membership_list_item);
+ long newestGroupId = -1;
+
mGroupMetaData.moveToPosition(-1);
while (mGroupMetaData.moveToNext()) {
String accountName = mGroupMetaData.getString(GroupMetaDataLoader.ACCOUNT_NAME);
@@ -317,6 +331,10 @@
long groupId = mGroupMetaData.getLong(GroupMetaDataLoader.GROUP_ID);
if (groupId != mFavoritesGroupId
&& (groupId != mDefaultGroupId || mDefaultGroupVisible)) {
+ if (groupId > newestGroupId) {
+ newestGroupId = groupId;
+ mAdapter.setNewestGroupPosition(mAdapter.getCount());
+ }
String title = mGroupMetaData.getString(GroupMetaDataLoader.TITLE);
boolean checked = hasMembership(groupId);
mAdapter.add(new GroupSelectionItem(groupId, title, checked));