0

これは、Flex モバイル プロジェクトの Flex コードです。エラーのある空白がある IList に Rss フィードをロードしたいと考えています。これまでのところ、Stringutil.trim(String)について知っています。しかし、リストを機能させるために使用する必要がある場所に行き詰まっています。お知らせ下さい。

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    xmlns:studierende="services.studierende.*"
    xmlns:allgemein="services.allgemein.*"
    xmlns:veranstaltung="services.veranstaltung.*"
    xmlns:wissenschaft="services.wissenschaft.*"
    overlayControls="false">
<fx:Script>
    <![CDATA[
        import flash.net.dns.AAAARecord;

        import mx.events.FlexEvent;
        import mx.utils.StringUtil;

        protected function openmenu(event:MouseEvent):void
        {}
        protected function reload(event:MouseEvent):void
        {
            asynclist.removeAll();
            getDataResult.token = feed1.getData();
        }

        protected function loadRSS(event:FlexEvent):void
        {
            getDataResult.token = feed1.getData();
            //I guess here is a good place to trim the whitespaces. But how ?

        }


        protected function loadfeed(event:MouseEvent,rid:Number):void
        {
            var rssid:Number = rid;
            switch(rssid)
            {
                case 0:
                    asynclist.removeAll();
                    getDataResult.token = feed1.getData();
                    break;
                case 1:
                    asynclist.removeAll();
                    getDataResult.token = feed2.getData();
                    break;
                 case 2:
                    asynclist.removeAll();
                    getDataResult.token = feed3.getData();
                    break; 
                 case 3:
                    asynclist.removeAll();
                    getDataResult.token = feed4.getData();
                    break; 
            }
        }


    ]]>
</fx:Script>
<fx:Declarations>
    <s:CallResponder id="getDataResult"/>
    <allgemein:Allgemein id="feed1"/>
    <studierende:Studierende id="feed2"/>
    <veranstaltung:Veranstaltung id="feed3"/>
    <wissenschaft:Wissenschaft id="feed4"/>
</fx:Declarations>
<s:navigationContent>
    <s:Button id="menubtn" label="Menu" click="openmenu(event)"/>
</s:navigationContent>
<s:actionContent>
    <s:Button id="reloadbtn" label="RELOAD" click="reload(event)"/>
</s:actionContent>
    <s:List id="list" left="10" right="10" top="50" bottom="10" creationComplete="loadRSS(event)"
            itemRenderer="icItemRender" labelField="title">
        <s:AsyncListView id="asynclist" list="{getDataResult.lastResult}" />
    </s:List>
<s:HGroup x="10" y="10" width="748" height="32">
    <s:Button height="32" label="Allgemein" fontSize="12" click="loadfeed(event,0)"/>
    <s:Button height="32" label="Studierende" fontSize="12" click="loadfeed(event,1)"/>
    <s:Button height="32" label="Veranstaltung" fontSize="12" click="loadfeed(event,2)"/>
    <s:Button height="32" label="Wissenschaft" fontSize="12" click="loadfeed(event,3)"/>
</s:HGroup>

4

2 に答える 2

0

リストの各要素に表示されるタイトルから空白を削除したいと考えています。

最も簡単な方法は、おそらく labelFunction を使用することです。次のようにリストに設定します。

<s:List id="list" left="10" right="10" top="50" bottom="10" creationComplete="loadRSS(event)"
        itemRenderer="icItemRender" labelFunction="myLabelFunction">

気づいた、あなたの labelField 宣言を削除しました。関数は次のようになります。

<fx:Script>
    <![CDATA[
        private function myLabelFunction(item:Object):String {
            return Stringutil.trim(item.title);
        }
    ]]>
</fx:Script>

カスタム itemRenderer を作成して、同じ最終結果を達成することもできます。

于 2012-11-11T22:15:28.437 に答える
0

カスタムアイテムレンダラーを介してフレクストラの助けを借りて物事を解決しました

package
{
import com.adobe.fiber.styles.Style;

import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
import flash.media.StageWebView;
import flash.net.URLRequest;
import flash.net.navigateToURL;

import mx.utils.StringUtil;

import spark.components.Button;
import spark.components.IconItemRenderer;
import spark.components.Image;
import spark.components.LabelItemRenderer;
import spark.components.supportClasses.StyleableTextField;


/**
 * 
 * ASDoc comments for this item renderer class
 * 
 */
public class asListItemRenderer extends IconItemRenderer
{
    private var titleDisplay:StyleableTextField;
    private var msgDisplay:StyleableTextField;
    private var link:String;
    private var readon:Image;
    private var stagewebview:StageWebView;
    private var warning:AlertPopUp;
    public function asListItemRenderer()
    {
        //TODO: implement function
        super();
        super.labelField = "title";
        super.messageField = "description";

    }

    /**
     * @private
     *
     * Override this setter to respond to data changes
     */
    override public function set data(value:Object):void
    {
        /*super.data = value;*/
        titleDisplay.text = value.title;
        msgDisplay.text = trimMessage(value);
        link = value.link;
        // the data has changed.  push these changes down in to the 
        // subcomponents here           
    } 

    /**
     * @private
     * 
     * Override this method to create children for your item renderer 
     */ 
    override protected function createChildren():void
    {
        titleDisplay = createDataField(false, false, "bold");
        addChild(titleDisplay);
        msgDisplay = createDataField(true, true);
        addChild(msgDisplay);
        readon = new Image();
        readon.source="assets/readmore_32px.png";
        readon.width=32;
        readon.height=32;
        addChild(readon);
        readon.addEventListener(MouseEvent.CLICK,openlink);

        // super.addEventListener(MouseEvent.CLICK,openlink);
        // create any additional children for your item renderer here
    }

    private function openlink(e:Event):void
    {


        /*if(StageWebView.isSupported==true){
            stagewebview=new StageWebView();
            stagewebview.viewPort=new Rectangle(0,0,stage.width,stage.height);
            stagewebview.stage=this.stage;
            stagewebview.loadURL(link);
        }else{
            warning = new AlertPopUp();
            warning.open(this);
        }*/
    }
    /**
     * @private
     * 
     * Override this method to change how the item renderer 
     * sizes itself. For performance reasons, do not call 
     * super.measure() unless you need to.
     */ 
    override protected function measure():void
    {
        //super.measure();
        // measure all the subcomponents here and set measuredWidth, measuredHeight, 
        // measuredMinWidth, and measuredMinHeight 
        measuredHeight = measuredMinHeight = 120;
        measuredWidth = measuredMinWidth = unscaledWidth;
    }

    /**
     * @private
     * 
     * Override this method to change how the background is drawn for 
     * item renderer.  For performance reasons, do not call 
     * super.drawBackground() if you do not need to.
     */
    override protected function drawBackground(unscaledWidth:Number, 
                                               unscaledHeight:Number):void
    {
        super.drawBackground(unscaledWidth, unscaledHeight);
        // do any drawing for the background of the item renderer here              
    }

    /**
     * @private
     *  
     * Override this method to change how the background is drawn for this 
     * item renderer. For performance reasons, do not call 
     * super.layoutContents() if you do not need to.
     */

    private function createDataField(multiline:Boolean = false, wordWrap:Boolean = false, style:String = "normal"):StyleableTextField
    {
        var labelField:StyleableTextField = new StyleableTextField();
        labelField.styleName = this;
        labelField.editable = false;
        labelField.selectable = false;
        labelField.multiline = multiline;
        labelField.wordWrap = wordWrap;
        labelField.setStyle("fontSize", 14);
        labelField.setStyle("color", 0x333333);
        labelField.setStyle("fontWeight", style);
        return labelField;
    }

    override protected function layoutContents(unscaledWidth:Number, 
                                               unscaledHeight:Number):void
    {
        setElementPosition(titleDisplay, 10, 10);
        setElementSize(titleDisplay, unscaledWidth, measuredMinHeight);
        setElementPosition(msgDisplay, 10, titleDisplay.y + 30);
        setElementSize(msgDisplay, unscaledWidth-50, measuredHeight);
        setElementPosition(readon,unscaledWidth-32,44);
        setElementSize(readon,32,32);
        // super.layoutContents(unscaledWidth, unscaledHeight);
        // layout all the subcomponents here   

    }
    private function trimMessage(item:Object):String {
        return StringUtil.trim(item.description);
    }

}
}
于 2012-11-12T01:46:10.743 に答える