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

  • Home
  • SEARCH
  • 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 6736013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:04:49+00:00 2026-05-26T11:04:49+00:00

I have an accelerometer app I am developing for Android, and I want to

  • 0

I have an accelerometer app I am developing for Android, and I want to start and stop the activity with a “start” and “stop” button. I am having trouble implementing the buttons in the code itself and I am looking for some help. Here is my main java file.

package com.*****.accelo;



import android.app.Activity;

import android.content.Context;

import android.hardware.Sensor;

import android.hardware.SensorEvent;

import android.hardware.SensorEventListener;

import android.hardware.SensorManager;

import android.os.Bundle;

import android.widget.TextView;

import android.widget.Button;

import android.view.View.OnClickListener;



public abstract class AcceloActivity extends Activity implements SensorEventListener,   
OnClickListener  {



TextView textViewX, textViewY, textViewZ, textViewError;
String blank;
Button buttonStop, buttonStart;

StringBuilder builderx = new StringBuilder();
StringBuilder buildery = new StringBuilder();
StringBuilder builderz = new StringBuilder();




public void onCreate(Bundle savedInstanceState){

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    textViewError = (TextView) findViewById(R.id.textViewError);
    textViewX = (TextView) findViewById(R.id.textViewX);
    textViewY = (TextView) findViewById(R.id.textViewY);
    textViewZ = (TextView) findViewById(R.id.textViewZ);
    buttonStart = (Button) findViewById(R.id.buttonStart);
    buttonStop = (Button) findViewById(R.id.buttonStop);

     //Button listener
    buttonStart.setOnClickListener(this);
    buttonStop.setOnClickListener( this);




    SensorManager manager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);

    Sensor accelerometer = manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

        if(!manager.registerListener(this, accelerometer, 
SensorManager.SENSOR_DELAY_UI)){



        }

textViewX.setText(blank);
textViewY.setText(blank);
textViewZ.setText(blank);
}




public void onAccuracyChanged(Sensor sensor, int accuracy) {



}



public void onSensorChanged(SensorEvent event) {

    builderx.setLength(0);
    buildery.setLength(0);
    builderz.setLength(0);

    builderx.append("X:  " + event.values[0]);
    buildery.append("Y: "+  event.values[1] );
    builderz.append("Z: " + event.values[2]);

    textViewX.setText(builderx.toString());
    textViewY.setText(buildery.toString());
    textViewZ.setText(builderz.toString());
    textViewError.setText(blank);

}

Thanks in advance!

  • 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-05-26T11:04:49+00:00Added an answer on May 26, 2026 at 11:04 am

    You get a reference to the buttons from the resources and then never do anything with them. What you do you mean by “having some trouble implementing”? If you’re having a specific problem or are encountering an error please add that information to the question so we can help you. If you just don’t know how to use buttons in Android there are a ton of good sites online but you should probably start here http://developer.android.com/reference/android/widget/Button.html.

    [Edits]

    Since this is your first language and first attempt to get something like this working let’s take a look at a few simple steps to begin with and then you can expand from there.

    I assume Googling for an answer is nearly reflexive at this point but here are a few good places to do some reading:

    • http://developer.android.com/reference/android/widget/Button.html (mentioned above)
    • http://developer.android.com/resources/browser.html?tag=sample (Android examples)
    • http://www.ibm.com/developerworks/opensource/library/os-android-sensor/ (sensor example from IBM)

    In general what you’ll need to do is override the onTouchEvent for your buttons http://developer.android.com/guide/topics/ui/ui-events.html so you can handle the user input and then record/compare the values you’re interested in. From what you’ve mentioned you want to do I’m not sure that extending the SensorEventListener is really what you want. If you’re just trying to capture the change from start to stop of your button clicks you can just handle the button events and record/analyze/display the data without worrying about the individual sensor updates. If, on the other hand, you actually want to display “live” sensor data between Start and Stop then you likely will need the SensorEventListener.

    Go through the Google tutorials and API guides, check out as many examples as you can find, and you should be on your way. Good luck with your project.

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

Sidebar

Related Questions

I have an Android app that allows the user to record data (such as
I am developing my first app for Android, and I wanted to know whether
I am developing an app using android OS for which I need to know
I want to use the vibration alert for the accelerometer action in an app
Ok, What the app is supposed to do: displays a start button, when pressed
I want to have a mobile-friendly website, in addition to a native app for
Possible Duplicate: accelerometer in Android emulator I have an application that plays music when
I am developing a Windows Phone 7 app and I want to tell the
I see many apps on the app store that have a button like calibrate
I have an app where u can move a man with the accelerometer. There

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.