0% found this document useful (0 votes)
1 views

Program_7R

The document outlines the creation of a user interface (UI) for an Android application using XML and Kotlin. It includes an activity layout with various views such as TextView, EditText, AutoCompleteTextView, Button, CheckBox, RadioGroup, Switch, ProgressBar, and ImageView, along with the corresponding Kotlin code to handle user interactions. Additionally, a custom theme is defined in the themes.xml file for the application.

Uploaded by

Siva Ranjini H
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Program_7R

The document outlines the creation of a user interface (UI) for an Android application using XML and Kotlin. It includes an activity layout with various views such as TextView, EditText, AutoCompleteTextView, Button, CheckBox, RadioGroup, Switch, ProgressBar, and ImageView, along with the corresponding Kotlin code to handle user interactions. Additionally, a custom theme is defined in the themes.xml file for the application.

Uploaded by

Siva Ranjini H
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Program 7: Create an UI with all views.

activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:orientation="vertical"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<!-- TextView -->


<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter your name:"
android:textSize="18sp" />

<!-- EditText -->


<EditText
android:id="@+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Your name here"
android:inputType="textPersonName" />

<!-- AutoCompleteTextView -->


<AutoCompleteTextView
android:id="@+id/autoComplete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Choose your country" />

<!-- Button -->


<Button
android:id="@+id/buttonGreet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Say Hello" />

<!-- CheckBox -->


<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I agree to the terms" />

<!-- RadioGroup with RadioButtons -->


<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<RadioButton
android:id="@+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male" />

<RadioButton
android:id="@+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
</RadioGroup>

<!-- Switch -->


<Switch
android:id="@+id/switchToggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enable notifications" />

<!-- ProgressBar (indeterminate) -->


<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:indeterminate="true" />

<!-- ImageView -->


<ImageView
android:id="@+id/imageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@mipmap/ic_launcher"
android:contentDescription="App Logo"
android:layout_marginTop="16dp" />

</LinearLayout>
</ScrollView>

MainActivity.kt:

package com.example.basicviews

import android.os.Bundle
import android.widget.*
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {


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

val nameEdit = findViewById<EditText>(R.id.editTextName)


val greetButton = findViewById<Button>(R.id.buttonGreet)
val textView = findViewById<TextView>(R.id.textView)
val autoComplete =
findViewById<AutoCompleteTextView>(R.id.autoComplete)

// Set up AutoCompleteTextView suggestions


val countries = arrayOf("India", "USA", "Canada", "Australia",
"Germany")
val adapter = ArrayAdapter(this,
android.R.layout.simple_dropdown_item_1line, countries)
autoComplete.setAdapter(adapter)

greetButton.setOnClickListener {
val name = nameEdit.text.toString()
textView.text = "Hello, $name!"
}
}
}

Themes.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.Basicviews"
parent="Theme.AppCompat.DayNight.NoActionBar" />
</resources>

You might also like