Issue
It's a simple idea. Not sure if I can do it in activity_main. In my layout I want to have it create table rows based on X. Still need to implement X. But for now I am not sure if it can be done.
// Where I try to create a while loop to loop the table row based on x.
var i = 0
var x = 3
while (i > x) {
println(i)
<TableRow
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="#ffffff">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:text=" order " />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:text="Del Note "
/>
</TableRow>
i++
}
</TableLayout>
Alright So I know now I am wrong and this is not how it should be done. Can I please be directed into a manner in which this can be done.
Solution
XML is only to be used for resources such as layouts, animations, vector images, and so forth. Kotlin cannot be directly implemented into an XML file, which is why every activity generates a Kotlin code file and a corresponding XML file.
What it looks like you are trying to do is display the same thing three times. For this you would need to use a Recycler View and use Kotlin to control what it does. You can read up on what a Recycler View on the Google Developer Documentation is and how to do this. Just a side note, at a beginner level a Recycler View can be very confusing just starting out.
Answered By - ToxicFlame427
Answer Checked By - Robin (JavaFixing Admin)