0

1 週間ほど前から問題に取り組んでいますが、まだ期待どおりに動作させることができませんでした。ItemRenderer として CheckBox と Label を持つ HBox を持つ DataGrid があります (以下のコードを参照)。セルをタップすると、標準の itemEditor がポップアップ表示され、ラベルの内容を入力できます。それが標準的な動作です。私は2つの問題を除いて正常に動作します:

  1. 多くのテキストを入力すると、水平スクロールバーがポップアップし、セルがそのスクロールバーでいっぱいになります。ご覧のとおり、 horizo​​ntalScrollPolicy をオフに設定しようとしましたが、まったく機能しません...すべての異なる要素に対してそれを実行しようとしましたが、失敗はまだ存在しています。

  2. 複数の行を埋めると、別の間違いが発生します。行をタップすると、データグリッドはその行の下にある行を選択します。これは、1 行が既に選択されている場合のみです。データグリッドの外側をタップしてから、任意の行をタップすると、右側の行の itemEditor が表示されます... set data メソッドの設定に何か問題がありますか?

__

package components
{
 import mx.containers.HBox;
 import mx.controls.CheckBox;
 import mx.controls.Label;

 public class ChoiceRenderer extends HBox
 {

  private var correctAnswer:CheckBox;
  private var choiceLabel:Label;

  public function ChoiceRenderer()
  {
   super();
   paint();
  }

  private function paint():void{
   percentHeight = 100;
   percentWidth = 100;
   setStyle("horizontalScrollPolicy", "off");
   super.setStyle("horizontalScrollPolicy", "off");

   correctAnswer = new CheckBox;
   correctAnswer.setStyle("horizontalScrollPolicy", "off");  
   addChild(correctAnswer);

   choiceLabel = new Label;
   choiceLabel.setStyle("horizontalScrollPolicy", "off");   
   addChild(choiceLabel);  


  }

     override public function set data(xmldata:Object):void{
      if(xmldata.name() == "BackSide"){
       var xmlText:Object = xmldata.TextElements.TextElement.(@position == position)[0];
       super.data = xmlText;
       choiceLabel.text = xmlText.toString();
       correctAnswer.selected = xmlText.@correct_answer;

      }               
 }
}

前もって感謝します!マーカス

4

2 に答える 2

0
  • これが問題の背後にある理由かどうかはわかりませんが、子を作成する標準的な方法はcreateChildrenメソッドをオーバーライドすることです。

  • また、ステートメントがありません-条件が失敗したときにelse呼び出していません。それもよく見えません。super.dataif

試す:

package components
{
 public class ChoiceRenderer extends HBox  {
  private var correctAnswer:CheckBox;
  private var choiceLabel:Label;

  public function ChoiceRenderer() {
    super();
    percentHeight = 100;
    percentWidth = 100;
    setStyle("horizontalScrollPolicy", "off");
  }
  override protected function createChildren():void {
    super.createChildren();
    correctAnswer = new CheckBox();
    addChild(correctAnswer);
    choiceLabel = new Label();
    choiceLabel.setStyle("horizontalScrollPolicy", "off");   
    addChild(choiceLabel);  
  }
  override public function set data(xmldata:Object):void {
    if(xmldata.name() == "BackSide") {
       var xmlText:Object = xmldata.TextElements.TextElement.(@position == position)[0];
       super.data = xmlText;
       choiceLabel.text = xmlText.toString();
       correctAnswer.selected = xmlText.@correct_answer;
    }
    else {
      //what if xmldata.name() is not "BackSide"?
      //you are not calling super.data in that case
    }
  }
}
于 2010-03-15T12:58:07.683 に答える
0
  • スクロールバーを避けるために、データグリッドの高さを可変にする必要があります

<mx:DataGrid id="dg"
 dataProvider="{dp}"
 variableRowHeight="true" 
 creationComplete="dg.height=dg.measureHeightOfItems(0,dp.length)+dg.headerHeight+2"/>
于 2010-03-15T15:46:51.783 に答える