I have the following XML layout driving my UI:
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:layout_margin="10dp" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username:" />
<EditText
android:id="@+id/txtUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" >
</EditText>
</TableRow>
<!-- more rows are here -->
</TableLayout>
I want to reuse this layout for another section of my app, but change something just slightly in one spot. I would like the EditText txtUsername to be changed to a TextView, in the same location and everything. So basically I am swapping out the EditText for a TextView in code.
How do I do this?
If that is the only change you need I would do it by adding the TextView into your layout (defaulted to View.GONE) and using View.setVisibility(View.VISIBLE) and View.setVisibility(View.GONE) where appropriate to swap them.
Then in your java you can leave the activity you already have the same, in the new activity(where you want the TextView instead) do something like this:
note that the two Views will need different values for their id.