ことをユーザーリリースまでときに、ユーザー押しボタン機能の繰り返し呼び出すことができ、私は繰り返すことができますどのようにがどのように私はアンドロイドでボタン
は、時間のユーザ押しボタンから関数を呼び出しますか?
私はclickClickListenerとlongclicklistenerをチェックしていますが、自分が望むようには見えません。
ありがとうございます。
ことをユーザーリリースまでときに、ユーザー押しボタン機能の繰り返し呼び出すことができ、私は繰り返すことができますどのようにがどのように私はアンドロイドでボタン
は、時間のユーザ押しボタンから関数を呼び出しますか?
私はclickClickListenerとlongclicklistenerをチェックしていますが、自分が望むようには見えません。
ありがとうございます。
:
public class MainActivity extends Activity implements OnTouchListener
{
private Button button;
// ...
@Override
public void onCreate(Bundle savedInstanceState)
{
// ...
button = (Button) findViewById(R.id.button_id);
button.setOnTouchListener(this);
// ...
}
// ...
@Override
public boolean onTouch(View v, MotionEvent event)
{
/* get a reference to the button that is being touched */
Button b = (Button) v;
/* get the action of the touch event */
int action = event.getAction();
if(action == MotionEvent.ACTION_DOWN)
{
/*
A pressed gesture has started, the motion contains
the initial starting location.
*/
}
else if(action == MotionEvent.ACTION_UP)
{
/*
A pressed gesture has finished, the motion contains
the final release location as well as any intermediate
points since the last down or move event.
*/
}
else if(action == MotionEvent.ACTION_MOVE)
{
/*
A change has happened during a press gesture (between
ACTION_DOWN and ACTION_UP). The motion contains the
most recent point, as well as any intermediate points
since the last down or move event.
*/
}
else if(action == MotionEvent.ACTION_CANCEL)
{
/*
The current gesture has been aborted. You will not
receive any more points in it. You should treat this
as an up event, but not perform any action that you
normally would.
*/
}
}
}
私が正しい場合: クリック:ユーザーが指を押して離しました。 タッチ:ユーザーの指がまだデバイスにあります。
多分あなたはonTouchListenerを試してみるべきですか?私はそれを使ったことがない ...
のように、ユーザがボタンのリリースまで機能を呼び出すためのOnTouchListener使用:あなたはOnTouchListener
を使用することができます
private OnTouchListener otl_conn = (OnTouchListener) new TouchListenerConn();
private Button bv = null;
bv = (Button) findViewById(R.id.xxxxbutton);
bv.setOnTouchListener(otl_conn);
class TouchListenerConn implements OnTouchListener
{
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
//call function here
break;
case MotionEvent.ACTION_UP:
//DO SOMETHING
xxxx....;
break;
}
return true;
}
}
私は(getLongPressTimeoutを調整することができます)ViewConfigurationでlongPressイベントが頻繁にチェックされるようにするには?私自身のLongPressイベントリスナーをより頻繁に実装しますか? – michael
また、TouchListenerを実装して、デフォルトのクリックアクションが正常に機能するようにするにはどうすればよいですか? – michael
[ボタンを押したままにしてアンドロイドリピートアクション]の複製が可能です(http://stackoverflow.com/questions/10511423/android-repeat-action-on-pressing-and-holding-a-button) – madx