Skip to content

Commit 6af9201

Browse files
committed
Create example which exposes view removal index issue
1 parent 8df52b8 commit 6af9201

File tree

8 files changed

+58
-12
lines changed

8 files changed

+58
-12
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ android {
1010
targetSdkVersion rootProject.ext.targetSdkVersion
1111
versionCode 1
1212
versionName "1.0"
13+
vectorDrawables.useSupportLibrary = true
1314
}
1415
buildTypes {
1516
release {

app/src/main/java/com/commit451/adapterlayout/sample/CheeseAdapter.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@ public void add(Cheese cheese) {
3636
public void removeLast() {
3737
if (!values.isEmpty()) {
3838
int removeIndex = values.size() - 1;
39-
values.remove(removeIndex);
40-
notifyItemRemoved(removeIndex);
39+
remove(removeIndex);
4140
}
4241
}
4342

43+
public void remove(int index) {
44+
values.remove(index);
45+
notifyItemRemoved(index);
46+
}
47+
4448
public void changeMiddle() {
4549
if (!values.isEmpty()) {
4650
int index = values.size()/2;
@@ -78,6 +82,13 @@ public void onClick(View v) {
7882
listener.onItemClicked(cheese);
7983
}
8084
});
85+
holder.buttonRemove.setOnClickListener(new View.OnClickListener() {
86+
@Override
87+
public void onClick(View v) {
88+
int position = AdapterLayout.getAdapterPosition(holder);
89+
remove(position);
90+
}
91+
});
8192
return holder;
8293
}
8394

app/src/main/java/com/commit451/adapterlayout/sample/CheeseViewHolder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ public static CheeseViewHolder inflate(ViewGroup parent) {
1818
}
1919

2020
public TextView title;
21+
public View buttonRemove;
2122

2223
public CheeseViewHolder(View view) {
2324
super(view);
2425
title = (TextView) view.findViewById(R.id.text);
26+
buttonRemove = view.findViewById(R.id.button_remove);
2527
}
2628

2729
public void bind(Cheese cheese) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:fillColor="#FFFFFFFF"
8+
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
9+
</vector>

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
<com.commit451.adapterlayout.AdapterLinearLayout
3939
android:id="@+id/adapter_layout"
40-
android:layout_width="wrap_content"
40+
android:layout_width="match_parent"
4141
android:layout_height="wrap_content"
4242
android:animateLayoutChanges="true"
4343
android:orientation="vertical" />
Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<TextView
2+
<LinearLayout
33
xmlns:android="http://schemas.android.com/apk/res/android"
4-
android:id="@+id/text"
5-
android:layout_width="wrap_content"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
xmlns:tools="http://schemas.android.com/tools"
6+
android:layout_width="match_parent"
67
android:layout_height="wrap_content"
7-
android:layout_margin="16dp"/>
8+
android:layout_margin="16dp"
9+
android:orientation="horizontal">
10+
11+
<TextView
12+
android:id="@+id/text"
13+
android:layout_width="0dp"
14+
android:layout_height="wrap_content"
15+
android:layout_gravity="center_vertical"
16+
android:gravity="center_vertical"
17+
android:layout_weight="1"
18+
tools:text="Cheese"/>
19+
20+
<ImageView
21+
android:id="@+id/button_remove"
22+
android:layout_width="wrap_content"
23+
android:layout_height="wrap_content"
24+
android:layout_gravity="center_vertical|right"
25+
android:background="?attr/selectableItemBackgroundBorderless"
26+
android:contentDescription="@null"
27+
android:padding="8dp"
28+
app:srcCompat="@drawable/ic_close_white_24dp"/>
29+
30+
</LinearLayout>

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
apply plugin: 'com.github.ben-manes.versions'
33
buildscript {
4-
ext.kotlinVersion = '1.1.2'
4+
ext.kotlinVersion = '1.1.51'
55
repositories {
66
jcenter()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:2.3.1'
9+
classpath 'com.android.tools.build:gradle:3.0.0-beta6'
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
1111
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
12-
classpath 'com.github.ben-manes:gradle-versions-plugin:0.14.0'
12+
classpath 'com.github.ben-manes:gradle-versions-plugin:0.15.0'
1313

1414
// NOTE: Do not place your application dependencies here; they belong
1515
// in the individual module build.gradle files
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed Apr 26 22:55:43 CDT 2017
1+
#Fri Sep 29 16:24:20 CDT 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

0 commit comments

Comments
 (0)