How to emulate double tap on one tap? - android

For example
mainEdit.setOnClickListener(new OnClickListener() {
int i = 0;
public void onClick(View v) {
//here something that causing double tap event
}
});
How can i archive that?

Android doesn't support double tap by default. You can kind of get the same effect by using a normal OnClickListener that stores a timestamp and checks to see if the stored value is close enough to the current time to count as a double click. You could even make your own Listener class that behaves this way. But I am unsure what you mean when you say: "here something that causing double tap event" Since nothing in android responds to double taps by default.

Related

floating View displaying on hover in android

I am trying to implement some hints when a user is hovering a button or another view, I see that android have support for onHoverListener but I don't understand how it really works. However I did try to find a solution how to make a floating editText on a button hover but I didn't find any ideas.
I am thinking that hover in android is the same think with long click because you can't hover with finger without clicking the view.
OnHoverListener is only implemented in 2 specific situations: a) when a Bluetooth or USB mouse is plugged into the device, or b) on Galaxy Note devices, when the S-Pen (stylus) is hovering over the object.
In specific setups/situations this can be a very neat feature, but unfortunately, most users will never even know it exists. For your situation, you may want to implement an OnLongClickListener for showing hints/tips as that is pretty standard in Android.
This example will show a TextView or ImageView hint for 5 seconds when a long-click is initiated:
btn.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View view) {
findViewById(R.id.hint).setVisibility(View.VISIBLE);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
findViewById(R.id.hint).setVisibility(View.GONE);
}
}, 5000);
return true;
}
});
Hope this helps,
I want to add up on Aaron's answer.
Some devices with sensitive screens - Samsung S5 comes to mind - don't even need an s-pen.
Just need to hold your finger 1/2 inch over the screen and it would trigger it.

How can I wait for button click in android?

I'm about to finish my Simon Says game, but I still have one crucial problem.
After my buttons are shown to the player, I have to wait (according to the level, e.g, if 5 buttons were showed to the user, I have to wait the user to click 5 buttons). I have searched around the internet, but the only answer was "You cannot freeze the android Application... blah blah blah".
Here it is my code:
public boolean playerTurn(){
//Enable buttons
buttonUp.setClickable(true);
buttonDown.setClickable(true);
buttonRight.setClickable(true);
buttonLeft.setClickable(true);
/*
Wait for a button clicks depends on the level, but HOW?
e.g, if the level is 5, I have to wait for 5 button clicks
and after it, I can continue to run the code
*/
/*Check if the user typed the correct order
*If pressed the correct order
*return true;
*else
*return false
*/
}
For each button do something like this:
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
buttonsPressedCount++;
if (buttonsPressedCount >= 5) {
// Do whatever you wanted to do
}
}
});
In this way, each button will listen for clicks and update a global counter. Finally when your global counter is greater than 5, you can proceed. The application is never "paused", it just only moves on the next section when five buttons have been clicked.
I'm not near a computer so no code example (will post later). Basically, you can set a class level counter. Provide an OnClickListener for each button - can be same or different. In the listener increment the counter and check if it reached 5 or not. If it did, check the pattern and clear counter.
You can use RxBindings for this purpose. Convert the clicks into a stream of events, and add a subscriber to it, which will react to the event of a click.
Here's how you can do it,
RxView.clicks(button)
.take(5)
.subscribe(aVoid ->
{
// Do your stuff
});
This will add a subscriber to the click event, and will only take the first five events.
Hope it helps.

Create a Button glSurfaceView in Android

I'm having a bit of a problem with this. I wanted to make a push button. However, I don't know how to use the Button class with OpenGL. I am not using the "R" class within Java instead I am using the old "assets" folder for compatibility.
I have it setup to find if you have touched the button and on "touch up" load the next screen. The flaw in this is that you can touch the screen and then drag your finger over to the button and then lift your finger. The next screen will load, because it has registered the touch up event at that position.
The easiest way to fix this would be to use the Button class, but how do I use it (especially because I won't be able to use findViewById)?
This is the code I was using but when onTouchUp check for a collision touchDown has magically changed to be the same as TouchUp?
private void onTouchDown(Vector2 point)
{
if (test.justUp)
{
test.setTouchDown(point);
test.justUp = false;
}
}
private void onTouchUp(Vector2 point)
{
test.setTouchUp(point);
test.justUp = true;
if(OverlapTester.pointInRectangle(test.bounds, test.touchUp) &&
OverlapTester.pointInRectangle(test.bounds, test.touchDown))
{
game.setScreen(new LevelSelect(game));
return;
}
}
When creating your own button class, register the "touch down" position and the "touch up" position. If they've both been registered inside your button graphic area, the button is pressed.

Capturing webview clicks (not just from links)

Is there some way to set an onClickListener for a webview? I've seen code here to intercept url clicks but I would just like to intercept anytime a user clicks the area the webview's on or swipes across it with their finger. I load html directly into the webview (as opposed to giving it a url) for formatting reasons and I'd really like to be able to tell any time the user clicks anywhere on the screen. I had been using a textview and that works fine, but is it doable with a webview?
Have you tried instead of an onClick, an onLongClick listener?
Taken from my recent project:
printMessageTextView.setOnLongClickListener(new OnLongClickListener() {
int active = 0;
#Override
public boolean onLongClick(View v) {
In this case, the int active = 0; is probably not needed. But should be able to listen for you.

Track amount of clicks user clicks button

I was wandering if there was any way to track the amount of clicks a user clicks a button.
I am creating a game and the user will only be allowed to take 5 turns. After these turns the user has lost the game.
I need to create maybe an if statement where the amount of clicks the user takes reaches > 5 then the user has lost. Is this possible.
I appreciate any help on this. Thanks
Edit:
Button link2Btn = (Button)findViewById( R.id.answerSelected );
link2Btn.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v)
{
i++;
getAnswer();
}
The get Answer method works fine except the if i > 5 statement within get Answer which is:
else if(i>5){
correctAnswer.setText("You have lost");
Use a flag variable and make an increment over a button press.
like
int i=0;
when button pressed
i++;
Now your condition
if(i>5){}

Categories

Resources