0

Delphi xe6 でカスタム ListBoxItem を作成しました (この投稿の @MikeSutton の回答に基づいて、Delphi Firemonkey でこの UI を作成するには、どのコントロールを使用する必要があります)

私はそこに2TNumberBoxと2を持ってTLabelsいます。これは私のカスタム リスト ボックス項目です

TListBoxItemMatchBet = class(TListBoxItem)
private
            ....
            //some other methods and properties
    fLeftValue: integer;
    procedure setLeftValue(const Value: integer);
    procedure setLeftValueStyle();
    procedure LeftValueChange(Sender: Tobject);

protected
    procedure ApplyStyle; override;
published
    property Text: string read fText write setText;
    property LeftValue: integer read fLeftValue write setLeftValue;
    property RightValue: integer read fRightValue write setRightValue;

end;

procedure TListBoxItemMatchBet.setLeftValue(const Value: integer);
begin
    fLeftValue := Value;
    setLeftValueStyle();

end;

procedure TListBoxItemMatchBet.setLeftValueStyle;
var
    O: TFMXObject;
begin
    O := FindStyleResource('nmbLeft'); // StyleName of the item
    if O is TNumberBox then
    begin
        TNumberBox(O).ValueType := TNumValueType.Integer;
        TNumberBox(O).Value := fLeftValue;
        TNumberBox(O).OnChange := LeftValueChange;
    end;

end;
procedure TListBoxItemMatchBet.ApplyStyle;
begin
    inherited;
    setTextStyle();
    setLeftValueStyle();
    setRightValueStyle();
end;

procedure TListBoxItemMatchBet.LeftValueChange(Sender: Tobject);
begin
    fLeftValue := round((Sender as TNumberBox).Value);
end;

リストボックスに多くの(約20)アイテムがあり、上にスクロールしない限り、すべて問題ありません。スクロールダウンすると、ナンバーボックスの値が他のレコードに変更されます(たとえば、値が50の場合、アイテムをスクロールバックすると値10 や 50 などの別のものに変更すると、他のリストボックス項目に移動します)。

この動作は、Android および Iphone シミュレーターで発生します。

ここにいくつかのスクリーンショットがあります。

設定値

設定値 (右上の列)


スクロールアップする

スクロールアップする


下へスクロール

下へスクロール

価値観が消えた

4

1 に答える 1

1

数日苦労した後、私は解決策を見つけました:

スタイルブックで目的のスタイルを作成し、このように ListBoxItem に項目を追加するだけです

TListBoxItem からのインスタンス化に注意してください

Itemx := TListBoxItem.Create(self);
Itemx.StyleLookup := 'listBoxItemNumericEditable';
Itemx.Text := 'A Title';

これがトリックです

Itemx.StylesData['nmbLeft.Value'] := 50;

また、このようなイベントハンドラーを追加することもできます

  Itemx.StylesData['nmbLeft.OnChange'] := TValue.From<TNotifyEvent>(DoNumberChange); 
于 2014-05-22T11:20:58.380 に答える