<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Peculiar C. Umeh</title>
    <description>The latest articles on Forem by Peculiar C. Umeh (@peculiaruc).</description>
    <link>https://forem.com/peculiaruc</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F487113%2F7afbd80c-4558-4596-97a6-51cd0d7123c8.jpeg</url>
      <title>Forem: Peculiar C. Umeh</title>
      <link>https://forem.com/peculiaruc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/peculiaruc"/>
    <language>en</language>
    <item>
      <title>Building Android Application with Jetpack Compose</title>
      <dc:creator>Peculiar C. Umeh</dc:creator>
      <pubDate>Mon, 21 Aug 2023 10:00:40 +0000</pubDate>
      <link>https://forem.com/peculiaruc/building-android-application-with-jetpack-compose-469m</link>
      <guid>https://forem.com/peculiaruc/building-android-application-with-jetpack-compose-469m</guid>
      <description>&lt;p&gt;Jetpack Compose is a modern toolkit for building native Android UIs. With Jetpack Compose, you can build beautiful, responsive, and flexible user interfaces using a declarative programming model. In this article, I will guide you through the process of building a simple Android application using Jetpack Compose.&lt;/p&gt;

&lt;p&gt;Prerequisites:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Android Studio Arctic Fox or later.&lt;/li&gt;
&lt;li&gt;Kotlin 1.5 or later&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To get started with Jetpack Compose, let's create  a new Android Studio project using the "Empty Compose Activity" template. The "Empty Compose Activity" template will create a project with the necessary dependencies and a basic Composable function that displays a "Hello, Android!" message.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Composable Functions&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
Composable functions are the building blocks of Jetpack Compose UIs. A Composable function is a Kotlin function that returns a UI element. Composable functions are annotated with the @Composable annotation.&lt;/p&gt;

&lt;p&gt;Here's an example of a Composable function that displays a text message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Composable
fun Greeting(name: String) 
{
    Text(
        text = "Hello $name!",
    )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this sample, the &lt;em&gt;greeting&lt;/em&gt; function takes a &lt;em&gt;name&lt;/em&gt; parameter and returns a &lt;em&gt;text&lt;/em&gt; UI element that displays a greeting message.&lt;br&gt;
If you want to change how this text looks or appears on your UI, you must use a Modifier. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Modifiers&lt;/strong&gt;&lt;br&gt;
Modifiers are used to change the appearance or behavior of a Composable element. Modifiers are functions that are called on a Composable element using the . operator.&lt;br&gt;
Here's an example of a Composable function that uses modifiers to change the appearance of a text element:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Text(
          text = "List of Courses",
          fontSize = "24.dp"
          modifier = Modifier.padding(top = 16.dp)
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this sample, I  used modifiers to add padding around the &lt;em&gt;text&lt;/em&gt; element and font size to increase the text size of the Text.&lt;br&gt;
A better way to make the UI more organized is to use layouts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Layouts&lt;/strong&gt;&lt;br&gt;
Layouts are used to arrange Composable elements on the screen. There are several built-in layouts in Jetpack Compose, such as &lt;em&gt;column, row, box,&lt;/em&gt; and &lt;em&gt;constraintLayout&lt;/em&gt;.&lt;br&gt;
Here's an example of a Composable function that uses the &lt;em&gt;column&lt;/em&gt; layout to display lists of composable elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Column(
      modifier = Modifier
          .fillMaxSize(1f)
          .padding(start = 6.dp, end = 6.dp)
  ) {

      Text(
          text = "List of Courses",
          modifier = Modifier.padding(top = 16.dp)
      )

      Spacer(modifier = Modifier.padding(8.dp))

     Row() {
         OutlinedTextField(
             value = textValue,
             onValueChange = { newTextValue -&amp;gt;
                 textValue =newTextValue

 } 
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;em&gt;column&lt;/em&gt; layout is used to arrange the &lt;em&gt;text&lt;/em&gt; elements vertically. A &lt;em&gt;spacer&lt;/em&gt; element is added after each element to separate it from another.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TextField&lt;/strong&gt;&lt;br&gt;
In jetpack compose TextField are used in place of EditText. TextFied has parameters such Value, onValueChange etc. &lt;br&gt;
Value is the expected input in the Textfield&lt;br&gt;
The onValueChanged is called whenever there is a new input to the TextField.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OutlinedTextField(
             value = textValue,
             onValueChange = { newTextValue -&amp;gt;
                 textValue =newTextValue

             } 
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The onValueChanged lambda returns a new value that you can use to update the Textfield state.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;State&lt;/strong&gt;&lt;br&gt;
State in an app is any value that can change over time. This is a very broad definition and encompasses everything from a Room database to a variable in a class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var textValue  by  remember {
        mutableStateOf("")

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;State is used to store and update the state of a Composable element. State is declared using the &lt;em&gt;remember&lt;/em&gt; function, which creates a &lt;em&gt;mutableState&lt;/em&gt; object that can be updated using the &lt;em&gt;setState&lt;/em&gt; function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Compare  RecyclerView on Kotlin and List is Jetpack Compose&lt;/strong&gt;&lt;br&gt;
RecyclerView and Jetpack Compose are both tools that can be used to display lists in Android applications, but they use different approaches to achieve this.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;RecyclerView&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
RecyclerView is a UI component in Android that is used to display large data sets in a list or grid format. It is part of the Android framework and is implemented in Java. It is used with an Adapter, which provides the data to be displayed and handles the creation and binding of Views.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MyAdapter(private val data: List&amp;lt;String&amp;gt;) : RecyclerView.Adapter&amp;lt;MyViewHolder&amp;gt;() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.list_item, parent, false)
        return MyViewHolder(view)
    }

    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        holder.bind(data[position])
    }

    override fun getItemCount(): Int {
        return data.size
    }

}
class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

    fun bind(item: String) {
        itemView.itemTextView.text = item
    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To use RecyclerView in Kotlin, you would create a RecyclerView in your layout XML file and then create an Adapter class that extends RecyclerView.Adapter. The Adapter class would define the data to be displayed and handle the creation and binding of Views. You would then set the Adapter on the RecyclerView in your Kotlin code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Jetpack Compose&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Jetpack Compose provides a more concise and intuitive way to build UIs compared to traditional Android layouts.&lt;br&gt;
In Jetpack Compose, you would create a Composable function that defines the UI for your list and use the LazyColumn or LazyRow layout to display the list. The LazyColumn or LazyRow layout creates and binds Views as needed, which makes it more efficient than traditional layouts.&lt;/p&gt;

&lt;p&gt;Let's implement this in our code.&lt;br&gt;
Look at an example of a basic Jetpack Compose implementation for displaying a list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Composable
fun LearnACourseList(courseTitle:List&amp;lt;String&amp;gt;) {

    LazyColumn(){

        items(courseTitle){ course -&amp;gt;
            CourseCard(course)

        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;em&gt;LearnACourseList&lt;/em&gt; function is a Composable function that takes a list of &lt;em&gt;String&lt;/em&gt; items and uses the &lt;em&gt;LazyColumn&lt;/em&gt; layout to display the list. The &lt;em&gt;items&lt;/em&gt; function is used to iterate over the &lt;em&gt;data&lt;/em&gt; list and create a Text Composable element for each item.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comparison&lt;/strong&gt;&lt;br&gt;
In terms of ease of use and development speed, Jetpack Compose is easier and faster to develop compared to RecyclerView. This is because Jetpack Compose uses a more concise and intuitive syntax, and it handles the creation and binding of Views automatically.&lt;/p&gt;

&lt;p&gt;In terms of performance, Jetpack Compose is also  considered to be more efficient compared to RecyclerView. Jetpack Compose uses a more efficient layout system that creates and binds Views as needed, which reduces memory usage and improves performance. However, the performance of Jetpack Compose may depend on the complexity of the UI and the number of items in the list.&lt;/p&gt;

&lt;p&gt;Find the link to the project &lt;a href="https://github.com/peculiaruc/LearnACourse"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>android</category>
      <category>jetpackcompose</category>
      <category>kotlin</category>
    </item>
    <item>
      <title>HacktoberFest, My First Experience.</title>
      <dc:creator>Peculiar C. Umeh</dc:creator>
      <pubDate>Thu, 29 Oct 2020 23:25:19 +0000</pubDate>
      <link>https://forem.com/peculiaruc/hacktoberfest-my-first-experience-27ek</link>
      <guid>https://forem.com/peculiaruc/hacktoberfest-my-first-experience-27ek</guid>
      <description>&lt;h3&gt;
  
  
  About me
&lt;/h3&gt;

&lt;h3&gt;
  
  
  The Journey
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Contributions
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Reflections
&lt;/h3&gt;

</description>
      <category>hacktoberfest</category>
    </item>
  </channel>
</rss>
