2

I’m creating an currency exchange rate application to learn Android. The app will list all exchange rate in a list, each of them has the layout like this (in essential):

<TableRow>
    <ImageView>
        [properties for the Flag image here]
    </ImageView>
    <TableLayout>
        <TableRow> 
            <TextView> [Buying] </TextView>
            <TextView> [Buying Rate] </TextView>
        </TableRow> 
        <TableRow> 
            <TextView> [Transfer] </TextView>
            <TextView> [Transfer Rate] </TextView>
        </TableRow> 
        <TableRow> 
            <TextView> [Selling] </TextView>
            <TextView> [Selling Rate] </TextView>
        </TableRow> 
    </TableLayout>
</TableRow>

To list exchange rate for all currencies I have the following approach:

 - Design the layout for one currency (let’s choose EUR as first currency)
 - Generate the layout for all other currencies automatically by:   
1.  Copy all properties of the EUR-layout into the new currency layout
2.  Modify some properties of new currency layout like: ID, Rates …
3.  Repeat steps 1,2 for all sub-layout of the new currency layout

But I don’t know how to code step 1, so I did a lot of google about: “android copy view” “android copy properties” “android copy view” “android clone view” “java clone object” …. but still no solution.

So, my question is: how to copy all properties of a view ?

hungson175
  • 4,373
  • 6
  • 22
  • 21

1 Answers1

4

Two approaches: look at LayoutInflater to inflate a sublayout from xml or use a ListView (which actually also uses the LayoutInflater in the end.)

Search for LayoutInflater here on SO for samples, i.e. What does LayoutInflater in Android do?

Community
  • 1
  • 1
Mathias Conradt
  • 28,420
  • 21
  • 138
  • 192
  • 1
    Thank you Mathias, I have done some reading based on your keywords, and solve the problem: Create a custom list view. Here are some useful reference, I hope they may help some beginner like me in the future: - Tutorial - Creating custom list view: http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/ - Creating views, which are taylor made to our need: The book "Professional Android 2 Application Development (Wrox Programmer to Programmer)" - Chapter 4 - Creating New Views – hungson175 Aug 22 '10 at 19:16
  • Your answer helped point me in the right direction. [I made an example](http://stackoverflow.com/a/41500409/3681880) to illustrate how all the properties of a view could be copied with `LayoutInflater`. – Suragch Jan 06 '17 at 06:53