質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Q&A

0回答

1010閲覧

Javaでアプリを作りたいのですがうまくできません

退会済みユーザー

退会済みユーザー

総合スコア0

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

0グッド

0クリップ

投稿2020/07/16 04:50

初めてアンドロイドスタジオでJavaを使ってアプリを作っています
スマホの傾きを加速度センサを使って調べたいのですが、なかなかうまくいきません
Main Activity
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.widget.TextView;

import android.os.Bundle;
public class MainActivity extends AppCompatActivity
implements SensorEventListener {

private SensorManager sensorManager; private TextView textView, textInfo; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Get an instance of the SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); textInfo = findViewById(R.id.text_info); // Get an instance of the TextView textView = findViewById(R.id.text_view); } @Override protected void onResume() { super.onResume(); // Listenerの登録 Sensor accel = sensorManager.getDefaultSensor( Sensor.TYPE_ACCELEROMETER); sensorManager.registerListener(this, accel, SensorManager.SENSOR_DELAY_NORMAL); sensorManager.registerListener(this, accel, SensorManager.SENSOR_DELAY_FASTEST); sensorManager.registerListener(this, accel, SensorManager.SENSOR_DELAY_GAME); sensorManager.registerListener(this, accel, SensorManager.SENSOR_DELAY_UI); } // 解除するコードも入れる! @Override protected void onPause() { super.onPause(); // Listenerを解除 sensorManager.unregisterListener(this); } @Override public void onSensorChanged(SensorEvent event) { float sensorX, sensorY, sensorZ; if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { sensorX = event.values[0]; sensorY = event.values[1]; sensorZ = event.values[2]; String strTmp = "加速度センサー\n" + " X: " + sensorX + "\n" + " Y: " + sensorY + "\n" + " Z: " + sensorZ; textView.setText(strTmp); } } @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { }

}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView android:id="@+id/text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="62dp" android:layout_marginLeft="62dp" android:layout_marginTop="135dp" android:layout_marginEnd="291dp" android:layout_marginRight="291dp" android:layout_marginBottom="577dp" android:text="TextView" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.64" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/text_info" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="77dp" android:layout_marginLeft="77dp" android:layout_marginTop="135dp" android:layout_marginEnd="157dp" android:layout_marginRight="157dp" android:layout_marginBottom="577dp" android:text="TextView" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/textView" app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

でやっていますが角度が表示されません
間違っているとこも多くあると思いますが、アドバイスをいただければ幸いです

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

m.ts10806

2020/07/16 06:49

Android および Android Studioのタグを追加してください。 また、コードはマークダウンのcode機能にてご提示ください
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問