Skip to content

Commit c5f07d4

Browse files
committed
Fix bauerca#77: OnClickListener crashes controller
Testing: add OnClickListener to TextView in CursorAdapter demo.
1 parent 739f317 commit c5f07d4

File tree

8 files changed

+49
-10
lines changed

8 files changed

+49
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
0.6.1
5+
-----
6+
7+
* Fix #77: OnClickListener in list item crashes
8+
DragSortController.
9+
410
0.6.0
511
-----
612

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ dependency to your pom.xml:
360360
<dependency>
361361
<groupId>com.mobeta.android.dslv</groupId>
362362
<artifactId>drag-sort-listview</artifactId>
363-
<version>0.6.0-SNAPSHOT</version>
363+
<version>0.6.1-SNAPSHOT</version>
364364
<type>apklib</type>
365365
</dependency>
366366
```

demo/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ Copyright 2012 Andreas Schildbach
2020
<parent>
2121
<groupId>com.mobeta.android.dslv</groupId>
2222
<artifactId>parent</artifactId>
23-
<version>0.6.0-SNAPSHOT</version>
23+
<version>0.6.1-SNAPSHOT</version>
2424
<relativePath>../pom.xml</relativePath>
2525
</parent>
2626

2727
<groupId>com.mobeta.android.demodslv</groupId>
2828
<artifactId>drag-sort-listview-demo</artifactId>
2929
<packaging>apk</packaging>
30-
<version>0.6.0-SNAPSHOT</version>
30+
<version>0.6.1-SNAPSHOT</version>
3131

3232
<dependencies>
3333
<dependency>

demo/src/com/mobeta/android/demodslv/CursorDSLV.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
import android.database.MatrixCursor;
77
import android.os.Bundle;
88
import android.support.v4.app.FragmentActivity;
9-
9+
import android.content.Context;
10+
import android.view.View;
11+
import android.view.ViewGroup;
12+
import android.database.Cursor;
13+
import android.widget.Toast;
1014

1115
public class CursorDSLV extends FragmentActivity {
1216

@@ -20,7 +24,7 @@ public void onCreate(Bundle savedInstanceState) {
2024

2125
String[] cols = {"name"};
2226
int[] ids = {R.id.text};
23-
adapter = new SimpleDragSortCursorAdapter(this,
27+
adapter = new MAdapter(this,
2428
R.layout.list_item_click_remove, null, cols, ids, 0);
2529

2630
DragSortListView dslv = (DragSortListView) findViewById(android.R.id.list);
@@ -36,4 +40,26 @@ public void onCreate(Bundle savedInstanceState) {
3640
}
3741
adapter.changeCursor(cursor);
3842
}
43+
44+
private class MAdapter extends SimpleDragSortCursorAdapter {
45+
private Context mContext;
46+
47+
public MAdapter(Context ctxt, int rmid, Cursor c, String[] cols, int[] ids, int something) {
48+
super(ctxt, rmid, c, cols, ids, something);
49+
mContext = ctxt;
50+
}
51+
52+
@Override
53+
public View getView(int position, View convertView, ViewGroup parent) {
54+
View v = super.getView(position, convertView, parent);
55+
View tv = v.findViewById(R.id.text);
56+
tv.setOnClickListener(new View.OnClickListener() {
57+
@Override
58+
public void onClick(View v) {
59+
Toast.makeText(mContext, "text clicked", Toast.LENGTH_SHORT).show();
60+
}
61+
});
62+
return v;
63+
}
64+
}
3965
}

library/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ Copyright 2012 Andreas Schildbach
2020
<groupId>com.mobeta.android.dslv</groupId>
2121
<artifactId>drag-sort-listview</artifactId>
2222
<packaging>apklib</packaging>
23-
<version>0.6.0-SNAPSHOT</version>
23+
<version>0.6.1-SNAPSHOT</version>
2424

2525
<parent>
2626
<groupId>com.mobeta.android.dslv</groupId>
2727
<artifactId>parent</artifactId>
28-
<version>0.6.0-SNAPSHOT</version>
28+
<version>0.6.1-SNAPSHOT</version>
2929
<relativePath>../pom.xml</relativePath>
3030
</parent>
3131

library/src/com/mobeta/android/dslv/DragSortController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public boolean startDrag(int position, int deltaX, int deltaY) {
236236

237237
@Override
238238
public boolean onTouch(View v, MotionEvent ev) {
239-
if (!mDslv.isDragEnabled()) {
239+
if (!mDslv.isDragEnabled() || mDslv.listViewIntercepted()) {
240240
return false;
241241
}
242242

@@ -246,7 +246,6 @@ public boolean onTouch(View v, MotionEvent ev) {
246246
}
247247

248248
int action = ev.getAction() & MotionEvent.ACTION_MASK;
249-
250249
switch (action) {
251250
case MotionEvent.ACTION_DOWN:
252251
mCurrX = (int) ev.getX();

library/src/com/mobeta/android/dslv/DragSortListView.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,7 @@ private void doActionUpOrCancel() {
16041604
mDragState = IDLE;
16051605
}
16061606
mCurrFloatAlpha = mFloatAlpha;
1607+
mListViewIntercepted = false;
16071608
mChildHeightCache.clear();
16081609
}
16091610

@@ -1623,6 +1624,12 @@ private void saveTouchCoords(MotionEvent ev) {
16231624
mOffsetY = (int) ev.getRawY() - mY;
16241625
}
16251626

1627+
public boolean listViewIntercepted() {
1628+
return mListViewIntercepted;
1629+
}
1630+
1631+
private boolean mListViewIntercepted = false;
1632+
16261633
@Override
16271634
public boolean onInterceptTouchEvent(MotionEvent ev) {
16281635
if (!mDragEnabled) {
@@ -1651,6 +1658,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
16511658
intercept = true;
16521659
} else {
16531660
if (super.onInterceptTouchEvent(ev)) {
1661+
mListViewIntercepted = true;
16541662
intercept = true;
16551663
}
16561664

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Copyright 2012 Andreas Schildbach
1919

2020
<groupId>com.mobeta.android.dslv</groupId>
2121
<artifactId>parent</artifactId>
22-
<version>0.6.0-SNAPSHOT</version>
22+
<version>0.6.1-SNAPSHOT</version>
2323
<packaging>pom</packaging>
2424

2525
<properties>

0 commit comments

Comments
 (0)