簡體   English   中英

我們是否可以更改布局xml文件中存在的視圖,以查看include標記內的視圖。

[英]Can we alter the Views present in the layout xml file for the Views present inside the include tag.

我試圖通過以下方法在另一個xml文件中重用已經創建的布局xml文件

我當前的XML文件如下:

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

    <include
        android:id="@+id/insertTask"
        layout="@layout/activity_edit_screen">

    </include>

</RelativeLayout>

布局文件activity_edit_screen有一個名為“Update”的按鈕,我想將該按鈕更改為“Add”。 這是兩個xml文件之間的唯一變化。 我怎么能這樣呢? 我試圖在另一個中重復使用一個xml。 請提供建議。 提前致謝。

嘗試在后面的代碼中重命名按鈕。

Button button=(Button)findViewByID(R.id.button1);
            button.setText("Add");

初始化視圖后,嘗試重命名onCreate()中的按鈕文本。

Button sample_btn=(Button)findViewById(R.id.sample_btn);
sample_btn.setText("Add")

;

暫無
暫無

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

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