I am new to jetpack compose and I am working on a little app. I've managed to understand how to create some elements and was trying to display them inside a Column. I managed to arrange everything how it should be in the preview but somehow it doesn't show up in the emulator.
I made sure to use the same @Composable in both the Preview and OnCreate calls but still the problem persists. Does anybody know the reason?
package net.colelli.gpacalculator
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Divider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import net.colelli.gpacalculator.elements.StaticRowElement
import net.colelli.gpacalculator.ui.theme.GPACalculatorTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
GPACalculatorTheme {
MainScreen()
}
}
}
}
@Composable
fun MainScreen(){
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Column(
modifier = Modifier.padding(5.dp)
) {
for(i in 1..10){
StaticRowElement(
itemNumber = 1,
subjectText = "Title",
grade = "30L",
usGrade = "A+",
gpaGrade = 4.0f
)
}
}
}
}
@Preview(showSystemUi = true)
@Composable
fun MainScreenPreview(){
GPACalculatorTheme {
MainScreen()
}
}
This is the result I get in both the preview and Emulator:

As said I tried to make sure I use the same function in both the preview and onCreate call and indeed I do. The expected result is like the one shown in the preview but I get the result shown on the emulator side.