Skip to content

Instantly share code, notes, and snippets.

@tmf16
Created February 25, 2014 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmf16/9203495 to your computer and use it in GitHub Desktop.
Save tmf16/9203495 to your computer and use it in GitHub Desktop.
ListViewを継承してonTouchEventを実装するとNullPointerException(Android 2.3以前)になるので回避策でgetChildCount使う実装
public class HogeListView extends ListView {
public HogeListView(Context context) {
super(context);
}
public HogeListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public HogeListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_MOVE:
// task
break;
default:
break;
}
if (getChildCount() == 0) {
return false;
}
return super.onTouchEvent(ev);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment