1. Home
  2. /
  3. Jetpack-compose
  4. /
  5. Jetpack Compose Todo With Priority

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.

Quick Explain

  • ▸Jetpack Compose allows developers to define UI components in Kotlin code using a declarative syntax.
  • ▸It replaces XML-based layouts, enabling more concise and reactive UI creation.
  • ▸Compose emphasizes unidirectional data flow, state management, and integration with modern Android architecture components.

Core Features

  • ▸Composable functions for UI elements
  • ▸State management with remember, mutableStateOf, and StateFlow
  • ▸Layouts like Column, Row, Box, LazyColumn
  • ▸Material and custom design system support
  • ▸Animation APIs for smooth UI transitions

Learning Path

  • ▸Learn Kotlin fundamentals
  • ▸Understand Composables and state management
  • ▸Explore layouts and modifiers
  • ▸Practice with Material components
  • ▸Integrate with ViewModel, LiveData, and navigation

Practical Examples

  • ▸Building a login form with TextField and Button
  • ▸Displaying a list with LazyColumn and items
  • ▸Reactive UI using ViewModel and StateFlow
  • ▸Implementing Material Design components
  • ▸Animating transitions and gestures between screens

Comparisons

  • ▸Android-native focus vs cross-platform frameworks like Flutter/Titanium
  • ▸Declarative UI vs XML layouts
  • ▸Tightly integrated with Kotlin and Jetpack
  • ▸Better state management vs traditional XML + LiveData
  • ▸Best for modern, reactive Android apps

Strengths

  • ▸Full native performance on Android
  • ▸Modern declarative programming style
  • ▸Tight integration with Kotlin and Android ecosystem
  • ▸Reusable and modular composable components
  • ▸Simplifies UI state handling and lifecycle management

Limitations

  • ▸Android-only (no cross-platform support)
  • ▸Requires Kotlin knowledge
  • ▸Still maturing compared to traditional XML-based UI
  • ▸Limited community resources compared to older frameworks
  • ▸May require refactoring legacy apps to adopt fully

When NOT to Use

  • ▸Cross-platform apps targeting iOS or web
  • ▸Legacy apps with minimal refactoring budget
  • ▸Apps requiring large pre-existing UI libraries in XML
  • ▸Small apps where traditional XML is sufficient
  • ▸Teams not familiar with Kotlin

Cheat Sheet

  • ▸`@Composable` - declares a composable function
  • ▸`remember { mutableStateOf() }` - local state
  • ▸`Modifier.padding(16.dp)` - styling and layout
  • ▸`LazyColumn { items(...) }` - scrollable lists
  • ▸`Scaffold` - basic screen structure with topBar and bottomBar

FAQ

  • ▸Is Compose free?
  • ▸Yes - part of Android Jetpack.
  • ▸Does Compose support iOS?
  • ▸No - Android-only.
  • ▸Can Compose replace XML layouts?
  • ▸Yes - declarative Kotlin-based UI.
  • ▸Does Compose support theming?
  • ▸Yes - Material3 theming and custom styles.
  • ▸Is Compose production-ready?
  • ▸Yes - stable since Jetpack Compose 1.0

30-Day Skill Plan

  • ▸Week 1: Basic composables (Text, Button, Image)
  • ▸Week 2: Layouts (Column, Row, Box, LazyColumn)
  • ▸Week 3: State management with remember and ViewModel
  • ▸Week 4: Material Design components and theming
  • ▸Week 5: Animations, gestures, and advanced UI patterns

Final Summary

  • ▸Jetpack Compose is the modern toolkit for building Android UIs in Kotlin.
  • ▸Declarative, reactive, and state-driven UI.
  • ▸Replaces XML layouts with composable functions.
  • ▸Full integration with Android architecture components.
  • ▸Ideal for modern, dynamic, and maintainable Android apps.

Project Structure

  • ▸MainActivity.kt - entry point of the app
  • ▸ui/ - folder for composable UI components
  • ▸theme/ - color, typography, and shape theming
  • ▸viewmodel/ - state management and business logic
  • ▸data/ - repository or data source integration

Monetization

  • ▸Publish apps to Google Play Store
  • ▸Enterprise app development
  • ▸Build reusable composable libraries
  • ▸Consulting on modern Android UI
  • ▸Rapid prototyping for clients

Productivity Tips

  • ▸Use Android Studio preview for fast iteration
  • ▸Reuse composables for consistency
  • ▸Leverage Material3 components
  • ▸Optimize state management to avoid recomposition
  • ▸Use Kotlin features effectively

Basic Concepts

  • ▸Composable: basic building block for UI
  • ▸State: holds UI data that can change
  • ▸Layouts: Column, Row, Box, LazyColumn, LazyRow
  • ▸Modifiers: styling and positioning elements
  • ▸Material components: Buttons, TextField, Scaffold, Snackbar

Official Docs

  • ▸https://developer.android.com/jetpack/compose
  • ▸https://github.com/androidx/compose-samples
  • ▸https://developer.android.com/guide/compose

More Jetpack-compose Typing Exercises

Jetpack Compose Simple Todo AppJetpack Compose Counter AppJetpack Compose Dark Mode CounterJetpack Compose Multi CounterJetpack Compose Auto Increment CounterJetpack Compose Countdown TimerJetpack Compose Counter With Alert

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher