将 TextView 设置为分贝强度的字符串 - Android Studio

Set TextView to the string for decibel strength - Android Studio

问题:

代码:

class wifi {
    int signalStrength = 0;
    int loopToggle = 0;
    Context context = MainActivity.this;

    @RequiresApi(api = Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    public void loop() throws InterruptedException {
        while (loopToggle == 0) {
            WifiManager signalStrength = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            String wifiInfo = WifiManager.EXTRA_WIFI_INFO;
            TextView textView = (TextView) textView.findViewById(readOut);
            Thread.sleep(1000);
        }
    }
}

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="com.example.wifilocator.MainActivity">

    <TextView
        android:id="@+id/readOut"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="filler"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

感谢您提供的任何帮助!

如果您引用具有 xml 属性的 View,则必须写 R.id.readOut android:id="@+id/readOut"

所以整行应该是

TextView textView = (TextView) textView.findViewById(R.id.readOut);

R 代表 R class 将生成包含您应用程序所需的各种资源。