2015-08-23 12 views
0

我有一個沒有高亮顯示選定鏈接的鏈接欄。 LinkBar有問題嗎?鏈接欄不是高亮選中的索引

這裏是我的代碼:

<mx:LinkBar id="languageTypeButtons" 
      selectedIndex="0" 
      itemClick="languageType_changeHandler(null)" 
      dataProvider="{languageTypes}"> 
</mx:LinkBar> 

<s:ArrayList id="languageTypes"> 
    <fx:String>{MXML}</fx:String> 
    <fx:String>{HTML}</fx:String> 
    <fx:String>{ANDROID}</fx:String> 
</s:ArrayList> 


public static const HTML:String = "HTML"; 
public static const MXML:String = "MXML"; 
public static const ANDROID:String = "Android"; 

我使用Flex 4.6和我有MX組件混合Spark組件。如果我在LinkBar MXML中設置了selectedIndex,那麼它會以可視方式停留在該項目上。它以編程方式更改,並且selectedIndex顯示正確的值。

更新
可能不知道這一點,所以我使用按鈕欄。不幸的是,ButtonBar似乎掛起整個應用程序,如果你沒有設置dataProvider或將其設置爲沒有項目的ArrayList。

+0

我不認爲你如果使用對象/字符串數組作爲數據提供者,可以設置LinkBar控件的'selectedIndex'。雖然如果您使用'ViewStack'作爲數據提供程序,或者使用'ToggleButtonBar'控件而不是'LinkBar',則可以設置'selectedIndex'。 –

+0

我設置了選定的索引,它返回我設置的值,但不會改變按鈕高亮。 –

回答

1

你必須使用ViewStack作爲數據提供程序:

<s:VGroup> 
    <mx:LinkBar id="languageTypeButtons" 
       selectedIndex="0" 
       itemClick="languageType_changeHandler()" 
       dataProvider="{languageTypesViewStack}"> 
    </mx:LinkBar> 
    <mx:ViewStack id="languageTypesViewStack" borderStyle="solid" width="100%" height="80%"> 
     <mx:Canvas id="htmlID" backgroundColor="#FFFFCC" label="{HTML}" width="100%" height="100%"> 
      <mx:Label text="HTML Selected" color="#000000"/> 
     </mx:Canvas> 
     <mx:Canvas id="mxmlID" backgroundColor="#CCFFFF" label="{MXML}" width="100%" height="100%"> 
      <mx:Label text="MXML Selected" color="#000000"/> 
     </mx:Canvas> 
     <mx:Canvas id="AndroidID" backgroundColor="#FFCCFF" label="{ANDROID}" width="100%" height="100%"> 
      <mx:Label text="Android Selected" color="#000000"/> 
     </mx:Canvas> 
    </mx:ViewStack> 

</s:VGroup> 

如果你真的想使用你的字符串的ArrayList作爲數據提供程序,然後在這裏是一個解決辦法:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:mx="library://ns.adobe.com/flex/mx" > 
<fx:Script><![CDATA[ 
    public static const HTML:String = "HTML"; 
    public static const MXML:String = "MXML"; 
    public static const ANDROID:String = "Android"; 

    private function languageType_changeHandler():void 
    { 
     var tempSelectedIndex:Number = languageTypeButtons.selectedIndex; 
     for (var i = 0; i < languageTypes.length; i++) 
     { 
      languageTypeButtons.selectedIndex = i 
      languageTypeButtons.validateNow(); 
     } 
     languageTypeButtons.selectedIndex = tempSelectedIndex; 
    } 

    ]]></fx:Script> 
<fx:Declarations> 
    <s:ArrayList id="languageTypes"> 
     <fx:String>{MXML}</fx:String> 
     <fx:String>{HTML}</fx:String> 
     <fx:String>{ANDROID}</fx:String> 
    </s:ArrayList> 
</fx:Declarations> 

<mx:LinkBar id="languageTypeButtons" 
      selectedIndex="0" 
      itemClick="languageType_changeHandler()" 
      dataProvider="{languageTypes}"> 
</mx:LinkBar> 

</s:Application> 
+0

我會選擇這個,因爲它在你的例子中有效,但記錄它在我的應用程序中不起作用。我已經逐字複製了它,並且所選的鏈接按鈕未被禁用。 –

+0

請您分享一下它的工作環境嗎? – gbdcool