Lab Detail


Sno Back Back Subject subject date title note
1 1 Back to subject Mobile Application Development Lab - 20A05706 (Lab) Sept. 14, 2025 RATING BAR

RATING BAR

E:\android\MyApplication\app\src\main\res\layout\activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Radio Button Example"
        android:textAllCaps="true"
        android:textStyle="italic"
        android:textSize="20sp"
        android:textColor="#309"
        android:padding="5dp"
        android:layout_margin="5dp"
        android:id="@+id/tv1"/>

    <RatingBar
        android:id="@+id/ratingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:stepSize="1"/>

</LinearLayout>

E:\android\MyApplication\app\src\main\java\com\example\myapplication\MainActivity.kt

package com.example.myapplication

import android.annotation.SuppressLint
import android.os.Bundle
import android.widget.RatingBar
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

    var ratingbar: RatingBar?=null
    @SuppressLint("WrongConstant")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // Enable edge-to-edge content
        enableEdgeToEdge()
        ratingbar = findViewById(R.id.ratingBar)
        ratingbar!!.setOnRatingBarChangeListener { ratingBar, fl, b ->
            Toast.makeText(applicationContext,"you seleted"+fl,Toast.LENGTH_LONG).show()
        }

    }
}

 

Output