Clear UsageProgressBarPreference image view before setting images
The legacy image view will be kept when setting different image view to UsageProgressBarPreference, this will cause UsageProgressBarPreference display duplicate views after setting many times, add removeAllViews() before addView() to fix it. Bug: 174964885 Test: atest UsageProgressBarPreferenceTest Change-Id: Id6b89dccb07a88f2f1be78a19c1de3ac3835087b
This commit is contained in:
committed by
Wesley Wang
parent
b6d634df79
commit
0ca9728f35
@@ -160,6 +160,7 @@ public class UsageProgressBarPreference extends Preference {
|
||||
customLayout.removeAllViews();
|
||||
customLayout.setVisibility(View.GONE);
|
||||
} else {
|
||||
customLayout.removeAllViews();
|
||||
customLayout.addView(mCustomImageView);
|
||||
customLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@@ -127,4 +127,20 @@ public class UsageProgressBarPreferenceTest {
|
||||
assertThat(customContent.getChildAt(0)).isEqualTo(imageView);
|
||||
assertThat(customContent.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCustomContent_setImageViewTwice_oneAndLatestChild() {
|
||||
final ImageView imageViewLegacy = mock(ImageView.class);
|
||||
final ImageView imageViewNew = mock(ImageView.class);
|
||||
mUsageProgressBarPreference.setCustomContent(imageViewLegacy);
|
||||
mUsageProgressBarPreference.setCustomContent(imageViewNew);
|
||||
|
||||
mUsageProgressBarPreference.onBindViewHolder(mViewHolder);
|
||||
|
||||
final FrameLayout customContent =
|
||||
(FrameLayout) mViewHolder.findViewById(R.id.custom_content);
|
||||
assertThat(customContent.getChildCount()).isEqualTo(1);
|
||||
assertThat(customContent.getChildAt(0)).isEqualTo(imageViewNew);
|
||||
assertThat(customContent.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user