2015-09-22 115 views
0

调用不同的看法我有一个可扩展列表视图,并且父“组”行中包含的TextView“为名称”和进度“的RSSI”。现在它代表 信号健康RSSI可以是20%,40%,60%,80%或100%,并且进度条应指示信号的状况。如何根据recived状态

所以我创建5个progressbars与机器人的值:进度=“”,根据该信号强度不同。

为例,

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% 

所以我创建显示withh不同进度百分比的progressbars的belwo xml文件。

现在我的问题是,什么是推荐的方式调用根据接收到的RSSI

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> 

回答

1

我要添加/动态显示你的进度条代码中的每个进度,你可以使用的方法set visibility(int VISIBILITY)随着不断View.VISIBLEView.INVISIBLE

不过,我认为这可能是更好的只有一个操作栏,并根据不断变化的RSSI(使用setProgress(int))您进度的进度。

2

我没有undarstand,为什么你创建5进度的显示进度,但是,如果你想显示进度条,你应该使用mProgressBar.setVisibility(View.Visible);和隐藏使用mProgressBar.setVisibility(View.GONE);

View.setVisibility(int)

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

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