2016-03-13 67 views
0

我有我的類字符串數組,在我的佈局ViewSwitcher無法切換視圖屬性在ViewSwitcher

 <ViewSwitcher 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/text_view_switcher"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/text"/> 

      <WebView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/text_webview"> 
      </WebView> 

我有兩個按鈕 - PreviousNext導航。當用戶點擊Next時,我將TextView和WebView的文本設置爲字符串數組的下一個元素。

的問題

我要實現以下目標:

if(string[index].contains("img src")) 
    show the Webview;   
else 
    show the textview; 

我該怎麼辦呢? ViewSwitcher.showNext沒有正確地完成這項工作。有什麼辦法可以將哪個視圖切換到使用ID?

回答

0

雖然不是一個解決方案,但一個簡單的解決方法是刪除ViewSwitcher,並保留兩個視圖 - TextViewWebView。現在,根據條件,可以切換視圖的可見性(GONEVISIBLE)。