Mobile Apps 2023W Lecture 12: Difference between revisions
Created page with " ==Code== <syntaxhighlight lang="kotlin" line> package carleton.comp2601.scrolldemo import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material.* import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment impor..." |
(No difference)
|
Revision as of 19:47, 17 February 2023
Code
package carleton.comp2601.scrolldemo
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import carleton.comp2601.scrolldemo.database.AppDatabase
import carleton.comp2601.scrolldemo.ui.theme.ScrollDemoTheme
class MainActivity : ComponentActivity() {
//val database: AppDatabase by lazy { AppDatabase.getDatabase(this) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ScrollDemoTheme {
// A surface container using the 'background' color from the theme
ScrollList()
//ScrollList(database)
}
}
}
}
@Composable
fun ScrollList() {
//fun ScrollList(database: AppDatabase) {
val listState = rememberLazyListState()
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colors.background
) {
Scaffold(
topBar = {
TopAppBar(
backgroundColor = MaterialTheme.colors.primary,
title = { Text("Scroll Demo") }
)
},
content = {
LazyColumn(
state = listState,
modifier = Modifier.fillMaxWidth(),
contentPadding = PaddingValues(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
) {
items(20000) { index ->
Text(text = "Item: $index")
}
}
}
)
}
}
//@Preview(showBackground = true)
//@Composable
//fun DefaultPreview() {
// ScrollDemoTheme {
// ScrollList()
// }
//}