私はgridviewを持っていますが、motioneven.action_downのものを実行し、motioneven.action_upのために何かをする必要があります...この必要な機能を私に与えてはいけません。Android onclicklistnerを使用せずにgridviewから選択した項目の位置を取得する方法、ontouchlistnerを代わりに使用する方法
gridviewを簡単に呼び出して、選択した項目をontouchlistenerで取得する方法はありますか?私は自分自身の実装を作ることには限界がありました。それは右のx、yを得るのは難しいので、もし私が子を呼び出すと、xとyは子に相対的なので、ボタンは0,0〜48,48になりますが、画面上の実際の位置は教えてくれませんグリッドビューまたはスクリーン自体を基準にしています。
これは私がやってきたことです、これまでのところ部分的に働いています。
Grid.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
int x = (int)event.getX();
int y = (int)event.getY();
int position = 0;
int childCount = Grid.getChildCount();
Message msg = new Message();
Rect ButtonRect = new Rect();
Grid.getChildAt(0).getDrawingRect(ButtonRect);
int InitialLeft = ButtonRect.left + 10;
ButtonRect.offsetTo(InitialLeft, ButtonRect.top);
//
while(position < childCount){
if(ButtonRect.contains(x,y)){break;}
if(ButtonRect.right + ButtonRect.width() > Grid.getWidth())
{ ButtonRect.offsetTo(InitialLeft, ButtonRect.bottom);}
position++;
ButtonRect.offsetTo(ButtonRect.right, ButtonRect.top);
}
msg.what = position;
msg.arg1 = ButtonRect.bottom;
msg.arg2 = y;
cHandler.sendMessage(msg);
}// end if action up
if (event.getAction() == MotionEvent.ACTION_UP) {
}
return false;
}
});
私はあなたがこの記事で答えを見つけるかもしれないと思う:http://stackoverflow.com/questions/2217670/android-how-to-detect-double-tap(あなたはまだそれを探している場合):) –