Hi all, this is probably a newbie question. but i'...
# android
k
Hi all, this is probably a newbie question. but i'm curious to know, whether in kotlin you can call components from other file into main file. i've tried to research about this before, but i can't find any resources that explaining about this stuff. here is the example of what i mean: main.xml
Copy code
<LinearLayout
   android:id="@+id/linear_main"
   xmlns:android="<http://schemas.android.com/apk/res/android>"
   xmlns:tools="<http://schemas.android.com/tools>"
   xmlns:app="<http://schemas.android.com/apk/res-auto>"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="horizontal"
   >

   <TextView
			android:layout_width="match_parent"
			android:layout_height="wrap_content"
			android:text="Hello World"
			android:textColor="@color/Black01"
			/>

  /*insert some kind of tag in here to call the id of new_image element from second_file.xml*/



</LinearLayout>
second_file.xml
Copy code
<LinearLayout
   android:id="@+id/linear_second"
   xmlns:android="<http://schemas.android.com/apk/res/android>"
   xmlns:tools="<http://schemas.android.com/tools>"
   xmlns:app="<http://schemas.android.com/apk/res-auto>"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="horizontal"
   >

   <ImageView
            android:id="@+id/new_image"
			android:layout_width="wrap_content"
			android:layout_height="wrap_content"
            app:srcCompat="@drawable/button_image"
			/>

</LinearLayout>
do note that the attached code in here is just an simple example code. as i would like to know, if it's possible or not to call only id of textview/imageview from the other xml file, into the main file.
j
you can use the include tag to re-use a layout in another https://developer.android.com/training/improving-layouts/reusing-layouts
k
yes, i know about include tag. it enable me to re use the existing layout into another one. but the problem with include tag is that it will include the whole layout. while what i would like to know is whether there's a tag to re-use "part"of that layout into another.
j
I don't think you can use a part of the layout. But you can make a new layout and merge it into your other layouts. Then you have e.g. layout A (imageview) layout B (include layout A) layout C (include layout A)
k
ahh ok, that's clear my curiosity about this matter. thanks for the answer. i'll think about better way when making new layout in the future.