Created
September 6, 2023 09:50
-
-
Save amoozeshbebin/b4d78daad8ed36e3c376bf1b8b4096bf to your computer and use it in GitHub Desktop.
List In JetPack Compose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MainActivity.kt: | |
import android.os.Bundle | |
import androidx.activity.ComponentActivity | |
import androidx.activity.compose.setContent | |
import androidx.compose.foundation.Image | |
import androidx.compose.foundation.layout.Arrangement | |
import androidx.compose.foundation.layout.Column | |
import androidx.compose.foundation.layout.Row | |
import androidx.compose.foundation.layout.Spacer | |
import androidx.compose.foundation.layout.fillMaxSize | |
import androidx.compose.foundation.layout.padding | |
import androidx.compose.foundation.layout.size | |
import androidx.compose.foundation.lazy.LazyColumn | |
import androidx.compose.material.MaterialTheme | |
import androidx.compose.material.Surface | |
import androidx.compose.material.Text | |
import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.remember | |
import androidx.compose.ui.Alignment | |
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.res.painterResource | |
import androidx.compose.ui.tooling.preview.Preview | |
import androidx.compose.ui.unit.dp | |
import com.example.newtest.ui.theme.NewTestTheme | |
class MainActivity : ComponentActivity() { | |
private var dataList = ArrayList<String>() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
init() | |
setContent { | |
NewTestTheme() { | |
Surface( | |
modifier = Modifier.fillMaxSize(), | |
color = MaterialTheme.colors.background | |
) { | |
listView() | |
} | |
} | |
} | |
} | |
@Preview(showBackground = true) | |
@Composable | |
fun listView(){ | |
LazyColumn{ | |
items(dataList.size){index -> | |
Text(text = dataList[index]) | |
Spacer(modifier = Modifier.size(3.dp)) | |
} | |
} | |
} | |
private fun init(){ | |
dataList.add("BMW E46") | |
dataList.add("Honda") | |
dataList.add("Benz") | |
dataList.add("Lambo") | |
dataList.add("BMW X6") | |
dataList.add("BMW X4") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment