I am making an app where the user holds down a button to make the phone vibrate and i'm not sure how to make it so only when the button is being held down it vibrates, my code so far is.
package one.two.bn;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;
import android.widget.Button;
import android.view.View.OnClickListener;
public class Vb extends Activity {
/** Called when the activity is first created. */
private Button button1;
private Vibrator vibrator;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button1 = (Button)findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
public void onClick(View v) {
if(v==button1){
vibrator.vibrate(300000);
}
}
If any on can help thanks a lot.