Monday, 9 September 2013

Can I implement this button here and modify some textView values? I keep getting error

Can I implement this button here and modify some textView values? I keep
getting error

package com.andineagoe.gradienttermic;
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class PressureAltimeterActivity extends Activity implements
SensorEventListener {
private PressureAltimeterActivity this_activity_;
protected Sensor sensor_pressure_;
protected SensorManager sensor_manager_;
protected double slp_inHg_;
protected double pressure_hPa_;
protected KalmanFilter pressure_hPa_filter_;
protected double last_measurement_time_;
private static final double SLT_K = 288.15;
private static final double TLAPSE_K_PER_M = -0.0065;
private static final double G_M_PER_S_PER_S = 9.80665;
private static final double R_J_PER_KG_PER_K = 287.052;
private static final double PA_PER_INHG = 3386;
private static final double FT_PER_M = 3.2808399;
private static final double KF_VAR_ACCEL = 0.0075;
private static final double KF_VAR_MEASUREMENT = 0.05;
Here I try to add my button and textviews and it works
**Button mButton = (Button) findViewById(R.id.saveButton);
TextView mPressure = (TextView) findViewById(R.id.pressureValue);
TextView mTemperature = (TextView) findViewById(R.id.tempValue);
TextView mLogSave = (TextView) findViewById(R.id.logSave);
Now I get 3-4 error when I try to set the onClick Listener Multiple
markers at this line - Syntax error on token "setOnClickListener", =
expected after this token - Syntax error on token(s), misplaced
construct(s)
The method onClick(View) of type PressureAltimeterActivity must override
or implement a supertype method Syntax error, insert "}" to complete
ClassBody
mButton.setOnClickListener(new View.onClickListner(){
@Override
public void onClick(View v){
//do stuff
});
public void saveData (){
}**
I just want to modify some log each time I press the button and I can't
seem to do so
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
pressure_hPa_filter_ = new KalmanFilter(KF_VAR_ACCEL);
setContentView(R.layout.main);
sensor_manager_ = (SensorManager)
getSystemService(SENSOR_SERVICE);
sensor_pressure_ =
sensor_manager_.getDefaultSensor(Sensor.TYPE_PRESSURE);
}
@Override
public void onResume() {
super.onResume();
this_activity_ = this;
if (slp_inHg_ < 28.1 || slp_inHg_ > 31.0) slp_inHg_ = 29.92;
pressure_hPa_ = 1013.0912;
pressure_hPa_filter_.reset(pressure_hPa_);
last_measurement_time_ = SystemClock.elapsedRealtime() / 1000.;
if (sensor_pressure_ != null) {
sensor_manager_.registerListener(this, sensor_pressure_,
SensorManager.SENSOR_DELAY_GAME);
}
}
@Override
public void onPause() {
super.onPause();
sensor_manager_.unregisterListener(this);
}
@Override
public void onDestroy() {
super.onDestroy();
}
protected void onSaveInstanceState(Bundle bundle) {
super.onSaveInstanceState(bundle);
bundle.putDouble("slp_inHg", slp_inHg_);
}
protected void onRestoreInstanceState(Bundle bundle) {
super.onRestoreInstanceState(bundle);
slp_inHg_ = bundle.getDouble("slp_inHg");
}
public boolean onKeyDown(int key_code, KeyEvent key_event) {
if (key_code != KeyEvent.KEYCODE_VOLUME_UP &&
key_code != KeyEvent.KEYCODE_VOLUME_DOWN) return false;
long slp_inHg_long = Math.round(100.0 * slp_inHg_);
if (key_code == KeyEvent.KEYCODE_VOLUME_UP) {
if (slp_inHg_long < 4031) ++slp_inHg_long;
} else if (key_code == KeyEvent.KEYCODE_VOLUME_DOWN) {
if (slp_inHg_long > 2028) --slp_inHg_long;
}
slp_inHg_ = slp_inHg_long / 100.0;
return true;
}
public boolean onKeyUp(int key_code, KeyEvent key_event) {
return key_code == KeyEvent.KEYCODE_VOLUME_UP ||
key_code == KeyEvent.KEYCODE_VOLUME_DOWN;
}
public void onAccuracyChanged(Sensor arg0, int arg1) {
}
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() != Sensor.TYPE_PRESSURE) return;
// Should not occur.
pressure_hPa_ = event.values[0];
final double curr_measurement_time =
SystemClock.elapsedRealtime() / 1000.;
final double dt = curr_measurement_time - last_measurement_time_;
pressure_hPa_filter_.update(pressure_hPa_, KF_VAR_MEASUREMENT,
dt);
last_measurement_time_ = curr_measurement_time;
double inaltime = (long)hPaToFeet(slp_inHg_,
pressure_hPa_filter_.getXAbs());
TextView textView = (TextView) findViewById(R.id.pressureValue);
textView.setText("" + inaltime);
}
private static double hPaToFeet(double slp_inHg, double
pressure_hPa) {
double factor_m = SLT_K / TLAPSE_K_PER_M;
double exponent = -TLAPSE_K_PER_M * R_J_PER_KG_PER_K /
G_M_PER_S_PER_S;
double current_sea_level_pressure_Pa = slp_inHg * PA_PER_INHG;
double altitude_m =
factor_m *
(Math.pow(100.0 * pressure_hPa /
current_sea_level_pressure_Pa, exponent) - 1.0);
return /**FT_PER_M* */ altitude_m;
}
}

No comments:

Post a Comment