gpt4 book ai didi

java - 我可以在这里实现这个按钮并修改一些 textView 值吗?我不断收到错误

转载 作者:行者123 更新时间:2023-11-30 03:23:23 26 4
gpt4 key购买 nike

    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;

在这里我尝试添加我的按钮和 TextView 并且它有效

        **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);

现在当我尝试设置 onClick 监听器时出现 3-4 错误此行有多个标记 - token “setOnClickListener”的语法错误,= 预期之后 这个 token - 标记语法错误,构造错误

PressureAltimeterActivity 类型的 onClick(View) 方法必须覆盖或实现父类(super class)型方法语法错误,插入“}”完成ClassBody

        mButton.setOnClickListener(new View.onClickListner(){

@Override
public void onClick(View v){

//do stuff

});

public void saveData (){

}**

我只想在每次按下按钮时修改一些日志,但我似乎无法这样做

        @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;
}

}

最佳答案

尝试将OnClickListener 实现到您的类和方法onClick,

public class LoginActivity extends Activity implements OnClickListener {

//...
@Override
public void onClick(View view) {
switch (view.getId()) {
case mButton.getId():
//implement action
break;

default:
break;
}
}
}

关于java - 我可以在这里实现这个按钮并修改一些 textView 值吗?我不断收到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18711801/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com