Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9166637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:11:49+00:00 2026-06-17T15:11:49+00:00

Here is my code for a add and subtraction program but the question is

  • 0

Here is my code for a add and subtraction program but the question is what is the best way to incoporate vibrations on the phone so for example the text layout shows -1 for a number.. So the phone then vibrates a certain way for -1.. I know I need to do a if statement, but I seem to be having trouble.. Here is the java code for the program.. And thank you for the help!

package com.example.untitled3;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MyActivity extends Activity {

    int counter;
    Button add , sub;
    TextView display;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        counter = 0;
        add = (Button) findViewById(R.id.bAdd);
        sub = (Button) findViewById(R.id.bSub);
        display = (TextView) findViewById(R.id.tvDisplay);


        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Adds 1 to the counter
                counter = counter + 1;
                display.setText(" Your total is :" + counter);
            }
        });

        sub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Subtract 1 from counter
                counter = counter - 1;
                display.setText(" Your total is :" + counter);
            }
        });
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:11:50+00:00Added an answer on June 17, 2026 at 3:11 pm

    You can make your phone vibrate using the following code:

    Vibrator vibe = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE) ;
    

    On some condition(In your case, when the text shows -1) call this:

    vibe.vibrate(200); // 200 is time in ms
    

    And don’t forget you need to add the permission to the manifest (after the </application> tag):

    <uses-permission android:name="android.permission.VIBRATE" />
    

    EDIT:

    Create an integer variable initialized to zero. Increment the variable on clicking the add button and decrement it on clicking the subtract button. Every time after the click check the value of the count variable, if it is zero then call the vibe.vibrate(200);.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add text to textarea in current pointer position, here's the code
here my simple code to add filename and their associated icon to virtualtreeview PFileInfoRec
here is the code. void sendMail() { MailMessage mail = new MailMessage(); mail.To.Add(abc@gmail.com); mail.From
I download the latest source code from here: http://aspnetwebstack.codeplex.com/SourceControl/list/changesets 1) add the system.web.mvc project
How can i reset a display:none and add some value here is the code
Here's the line from App.Config: <add key=CheckFileFormatString value=P{0}\t&quot;{1}, {2}&quot;\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}/> Here's the code that puts
I'm trying to add controller to my Todo list app. Here's the code. $(function(){
I just wonder how to add annotation in matlab plot? Here is my code:
Here is an old add in to quickly comment out HTML code. Maybe I
Here's some basic code to create a ListViewGroup, add it to the Groups collection

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.