簡體   English   中英

如何設置動態展開視圖中包含的按鈕的文本?

[英]How to set text of a button contained within a dynamically inflated view?

我正在嘗試動態設置在運行時膨脹的按鈕的文本,但未設置文本。

我創建一個自定義對話框為我設定SetContentView一個View ,我在運行時膨脹。 該視圖包含一個Button ,例如:

var dialog = new SetUnsetDialog();

var view = View.Inflate(_context, Resource.Layout.view_set_unset_buttons, null);

view.FindViewById<Button>(Resource.Id.btnPartsetA).Text = _blockDescriptions["partseta"];

dialog.SetContentView(view);
dialog.SetTitle("Set/Unset " + _area);
dialog.Show();

布局定義為:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <!-- irrelevant stuff removed -->

    <LinearLayout
        android:id="@+id/linearLayoutSetUnsetButtons"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center">

        <!-- irrelevant stuff removed -->

        <Button
            android:id="@+id/btnPartsetA"
            android:background="@null"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:drawableTop="@drawable/partset_a" />            

        <!-- irrelevant stuff removed -->

    </LinearLayout>
</LinearLayout>

為什么未設置按鈕文字? 我需要做什么設置?

更新:

事實證明這不是問題。 內容視圖稍后會重置,並覆蓋我設置的值。

使用setText方法而不是.Text怎么樣?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM