0
0
Android Kotlinmobile~20 mins

Why Android dominates mobile market share in Android Kotlin - Build It to Prove It

Choose your learning style9 modes available
Build: Market Share Info
This screen shows reasons why Android dominates the mobile market share in a simple list format.
Target UI
-------------------------
| Market Share Info      |
|-----------------------|
| Reasons Android Wins:  |
| 1. Open Source        |
| 2. Wide Device Range  |
| 3. Affordable Prices  |
| 4. Customization      |
| 5. Google Services    |
|                       |
| [Refresh]             |
-------------------------
Display a title at the top
Show a numbered list of 5 reasons why Android dominates
Add a Refresh button at the bottom
When Refresh is tapped, show a Toast message 'Data refreshed!'
Starter Code
Android Kotlin
package com.example.marketshareinfo

import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // TODO: Initialize RecyclerView and Button here
    }
}
Task 1
Task 2
Task 3
Solution
Android Kotlin
package com.example.marketshareinfo

import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView

class MainActivity : AppCompatActivity() {
    private val reasons = listOf(
        "Open Source",
        "Wide Device Range",
        "Affordable Prices",
        "Customization",
        "Google Services"
    )

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val recyclerView = findViewById<RecyclerView>(R.id.recyclerView)
        recyclerView.layoutManager = LinearLayoutManager(this)
        recyclerView.adapter = ReasonsAdapter(reasons)

        val refreshButton = findViewById<Button>(R.id.refreshButton)
        refreshButton.setOnClickListener {
            Toast.makeText(this, "Data refreshed!", Toast.LENGTH_SHORT).show()
        }
    }
}

class ReasonsAdapter(private val items: List<String>) : RecyclerView.Adapter<ReasonsAdapter.ViewHolder>() {
    class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val textView: TextView = view.findViewById(R.id.reasonText)
    }

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

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.textView.text = "${position + 1}. ${items[position]}"
    }

    override fun getItemCount(): Int = items.size
}

This app screen uses a RecyclerView to show a numbered list of reasons why Android dominates the mobile market. The list is simple and fixed. The Refresh button at the bottom shows a Toast message when tapped, simulating a data refresh.

The RecyclerView uses a LinearLayoutManager for vertical scrolling. The adapter binds each reason with its number prefix. This keeps the UI clean and easy to read.

This approach is common in Android apps to display lists efficiently and handle user actions like button taps.

Final Result
Completed Screen
-------------------------
| Market Share Info      |
|-----------------------|
| Reasons Android Wins:  |
| 1. Open Source        |
| 2. Wide Device Range  |
| 3. Affordable Prices  |
| 4. Customization      |
| 5. Google Services    |
|                       |
| [Refresh]             |
-------------------------
User taps Refresh button
A small popup (Toast) appears with text 'Data refreshed!'
Stretch Goal
Add a dark mode toggle button that switches the screen background and text colors.
💡 Hint
Use AppCompatDelegate.setDefaultNightMode() to switch between MODE_NIGHT_YES and MODE_NIGHT_NO.