Android 如何根据接收到的状态调用不同的视图

Android 如何根据接收到的状态调用不同的视图,android,progress-bar,views,android-progressbar,Android,Progress Bar,Views,Android Progressbar,我有一个可扩展的列表视图,父“组”行包含TextView“代表名称”和ProgressBar“代表RSSI”。现在是代表 信号运行状况可以是20%、40%、60%、80%或100%,进度条应指示信号的运行状况 因此,我创建了5个progressbars,其值为android:progress=“”根据信号强度不同而不同 比如, if the RSSI = -70; I should display the progressBar with 20% if the RSSI = -50; I sh

我有一个可扩展的列表视图,父“组”行包含TextView“代表名称”和ProgressBar“代表RSSI”。现在是代表 信号运行状况可以是20%、40%、60%、80%或100%,进度条应指示信号的运行状况

因此,我创建了5个progressbars,其值为android:progress=“”根据信号强度不同而不同

比如,

if the RSSI = -70; I should display the progressBar with 20%

if the RSSI = -50; I should display the progressBar with 40%

if the RSSI = -30; I should display the progressBar with 60%

if the RSSI = -10; I should display the progressBar with 80%
因此,我创建了belwo xml文件,该文件显示具有不同进度百分比的进度条

现在我的问题是,根据收到的RSSI,建议如何调用每个progressbar

xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:paddingTop="10dp"
tools:context=".ProgressBarTutorial" >

<ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:progressDrawable="@drawable/progress"
    android:progress="20" />

<ProgressBar
    android:id="@+id/progressBar2"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:progressDrawable="@drawable/progress"
    android:layout_below="@+id/progressBar1"
    android:layout_marginTop="30dp"
    android:progress="40"/>

<ProgressBar
    android:id="@+id/progressBar3"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:progressDrawable="@drawable/progress"
    android:layout_below="@+id/progressBar2"
    android:layout_marginTop="30dp"
    android:progress="60"/>

<ProgressBar
    android:id="@+id/progressBar4"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:progressDrawable="@drawable/progress"
    android:layout_below="@+id/progressBar3"
    android:layout_marginTop="30dp"
    android:progress="80"/>

<ProgressBar
    android:id="@+id/progressBar5"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:progressDrawable="@drawable/progress"
    android:layout_below="@+id/progressBar4"
    android:layout_marginTop="30dp"
    android:progress="100"/>

</RelativeLayout>

如果要在代码中动态添加/显示进度条,可以使用方法
设置可见性(int visibility)
和常量
View.VISIBLE
View.VISIBLE


但是,我认为最好只有一个操作栏,并根据进度栏上的RSSI更改进度(使用
setProgress(int))

如果要在代码中动态添加/显示进度栏,可以使用方法
set visibility(int visibility)
带有常量
视图。可见
视图。不可见


但是,我认为最好只有一个操作栏,并根据进度栏上的RSSI更改进度(使用
setProgress(int))

如果要在代码中动态添加/显示进度栏,可以使用方法
set visibility(int visibility)
带有常量
视图。可见
视图。不可见


但是,我认为最好只有一个操作栏,并根据进度栏上的RSSI更改进度(使用
setProgress(int))

如果要在代码中动态添加/显示进度栏,可以使用方法
set visibility(int visibility)
带有常量
视图。可见
视图。不可见


但是,我认为最好只有一个操作栏,并根据进度栏上的RSSI更改进度(使用
setProgress(int))

我没有理解,为什么创建5个进度栏来显示进度,但是,如果要显示进度栏,应该使用
mProgressBar.setVisibility(View.Visible);和隐藏使用
mProgressBar.setVisibility(View.GONE)

在我看来,要访问progressBars,可以使用
Map
类的一些实现。(
HashMap
例如)


如果您只想显示进度,最好的解决方案是使用
ProgressBar.setProgress(int)

我没有理解,为什么您创建了5个ProgressBar来显示进度,但是,如果您想显示ProgressBar,您应该使用
mProgressBar.setVisibility(View.Visible)和隐藏使用
mProgressBar.setVisibility(View.GONE)

在我看来,要访问progressBars,可以使用
Map
类的一些实现。(
HashMap
例如)


如果您只想显示进度,最好的解决方案是使用
ProgressBar.setProgress(int)

我没有理解,为什么您创建了5个ProgressBar来显示进度,但是,如果您想显示ProgressBar,您应该使用
mProgressBar.setVisibility(View.Visible)和隐藏使用
mProgressBar.setVisibility(View.GONE)

在我看来,要访问progressBars,可以使用
Map
类的一些实现。(
HashMap
例如)


如果您只想显示进度,最好的解决方案是使用
ProgressBar.setProgress(int)

我没有理解,为什么您创建了5个ProgressBar来显示进度,但是,如果您想显示ProgressBar,您应该使用
mProgressBar.setVisibility(View.Visible)和隐藏使用
mProgressBar.setVisibility(View.GONE)

在我看来,要访问progressBars,可以使用
Map
类的一些实现。(
HashMap
例如)

如果您只想显示进度,最好的解决方案是使用
ProgressBar.setProgress(int)