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

时间:2018-04-04 19:02:48

标签: android variables textview set

问题:

  • 设置id为" readOut"的textView对wifi信号强度的值测试

代码:

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>

感谢您提供的任何帮助!

1 个答案:

答案 0 :(得分:1)

如果您引用带有xml属性awk '/money/{sum+=$3} END{print sum}' Input_file 的{​​{1}}

,则必须写R.id.readOut

所以整行应该是

View

R 代表http://doc.qt.io/qt-5/qtqml-cppintegration-overview.html类,它将生成为包含您应用中所需的各种资源。