では、DynamicListView.java に 3 つの大きな変更を加えました。
1)セッターを以下のsetOnItemClickListenerに変更しました
public void init(Context context) {
setOnItemClickListener(mOnItemClickListener);
//setOnScrollListener(mScrollListener);
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
mSmoothScrollAmountAtEdge = (int) (SMOOTH_SCROLL_AMOUNT_AT_EDGE / metrics.density);
}
2)キャッチブロック例外を使用して、onItemLongClickListenerの代わりにそのonItemClickListenerを使用しました
public AdapterView.OnItemClickListener mOnItemClickListener = new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
long id){
try {
mTotalOffset = 0;
//Toast.makeText(getContext(), "OnItemClickListener", 100).show();
int position = pointToPosition(mDownX, mDownY);
int itemNum = position - getFirstVisiblePosition();
View selectedView = getChildAt(itemNum);
mMobileItemId = getAdapter().getItemId(position);
mHoverCell = getAndAddHoverView(selectedView);
selectedView.setVisibility(INVISIBLE);
mCellIsMobile = true;
updateNeighborViewsForID(mMobileItemId);
} catch (Exception e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
}
};
3) 下のコードを変更して、キーを押したときに同時にキー アップ イベントを呼び出し、その結果 onItemClickListener を呼び出すようにしました。
それについて私を悩ませている唯一のことは、ホバービューをすばやくタッチするとそこにとどまりますが、もう一度押すと消えてしまうことです。
@オーバーライド
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
//Toast.makeText(getContext(),"previously touched = true",Toast.LENGTH_SHORT).show();
if (passThroughActionUp){touchEventsEnded();passThroughActionUp = false; }
passThroughActionDown = true;
mDownX = (int) event.getX();
mDownY = (int) event.getY();
mActivePointerId = event.getPointerId(0);
event.setAction(MotionEvent.ACTION_UP);
break;
case MotionEvent.ACTION_MOVE:
if (mActivePointerId == INVALID_POINTER_ID) {
break;
}
//Toast.makeText(getContext()," passthroughActionMove = true",Toast.LENGTH_SHORT).show();
int pointerIndex = event.findPointerIndex(mActivePointerId);
mLastEventY = (int) event.getY(pointerIndex);
int deltaY = mLastEventY - mDownY;
//mCellIsMobile being true means that you are in a dragging event.
if (mCellIsMobile) {
mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left,
mHoverCellOriginalBounds.top + deltaY + mTotalOffset);
mHoverCell.setBounds(mHoverCellCurrentBounds);
invalidate();
handleCellSwitch();
mIsMobileScrolling = false;
handleMobileCellScroll();
return false;
}
break;
case MotionEvent.ACTION_UP:
//if (passThroughActionDown){touchEventsEnded();passThroughActionDown = false; break;}
passThroughActionUp = true;
touchEventsEnded();
break;
case MotionEvent.ACTION_CANCEL:
touchEventsCancelled();
break;
case MotionEvent.ACTION_POINTER_UP:
/*
* If a multitouch event took place and the original touch dictating
* the movement of the hover cell has ended, then the dragging event
* ends and the hover cell is animated to its corresponding position
* in the listview.
*/
pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
final int pointerId = event.getPointerId(pointerIndex);
if (pointerId == mActivePointerId) {
touchEventsEnded();
}
break;
default:
break;
}
return super.onTouchEvent(event);
}