Jetpack Compose Todo With Priority - Jetpack-compose Typing CST Test
Loading…
Jetpack Compose Todo With Priority — Jetpack-compose Code
Todo app where each task has a priority and displays it.
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.text.*
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
PriorityTodoApp()
}
}
}
@Composable
fun PriorityTodoApp() {
var todos by remember { mutableStateOf(listOf<Pair<String,String>>()) }
var task by remember { mutableStateOf("") }
var priority by remember { mutableStateOf("") }
Column(modifier = Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {
Row {
TextField(value = task, onValueChange = { task = it }, modifier = Modifier.weight(1f), placeholder = { Text("Task") })
TextField(value = priority, onValueChange = { priority = it }, modifier = Modifier.weight(1f), placeholder = { Text("Priority") })
Button(onClick = {
if(task.isNotBlank()) {
todos = todos + (task to priority)
task = ""; priority = ""
}
}) { Text("Add") }
}
Column {
todos.forEach { Text("${it.first} (Priority: ${it.second})") }
}
}
}Jetpack-compose Language Guide
Jetpack Compose is Android’s modern toolkit for building native UI using Kotlin, offering a declarative approach to designing app interfaces and simplifying UI development for Android.
Primary Use Cases
- ▸Native Android app development
- ▸Apps requiring reactive UI updates
- ▸Modernizing legacy Android apps
- ▸Enterprise Android apps with dynamic content
- ▸Rapid prototyping of Android interfaces
Notable Features
- ▸Declarative UI design in Kotlin
- ▸Composable functions for reusable UI elements
- ▸Integration with ViewModel and LiveData/StateFlow
- ▸Material Design components and theming
- ▸Hot reload and fast preview in Android Studio
Origin & Creator
Developed by Google and introduced in 2019 to modernize Android UI development with a declarative approach using Kotlin.
Industrial Note
Jetpack Compose is widely used for modern Android apps, enterprise applications, and apps that require dynamic UI updates and reactive components.