0% found this document useful (0 votes)
8 views2 pages

Sharedprefe

The document contains an Android application code that utilizes Shared Preferences to save and retrieve user input for name and roll number. It includes a Kotlin class 'MainActivity' with methods to handle button clicks for saving and getting data, along with an XML layout defining the user interface elements. The layout features EditText fields for user input and buttons to trigger save and retrieve actions.
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)
8 views2 pages

Sharedprefe

The document contains an Android application code that utilizes Shared Preferences to save and retrieve user input for name and roll number. It includes a Kotlin class 'MainActivity' with methods to handle button clicks for saving and getting data, along with an XML layout defining the user interface elements. The layout features EditText fields for user input and buttons to trigger save and retrieve actions.
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

SYCS51 Android Development 30/01/25

[Link]

package [Link]
import [Link]
import [Link]
import [Link].*
class MainActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
setContentView([Link].activity_main)
val etname= findViewById<EditText>([Link])
val etrollno= findViewById<EditText>([Link])
val save= findViewById<Button>([Link])
val get= findViewById<Button>([Link])
val sharedPref= getSharedPreferences("addName", MODE_PRIVATE)
var edit =[Link]()
[Link]{
[Link]("name", [Link]())
[Link]("rollno", [Link]())
[Link]()
[Link](this, "data saved" , Toast.LENGTH_SHORT).show()
}
[Link]{
val myname= [Link]("name", "default value")
val myroll= [Link]("rollno","default value")
[Link](this, " Name: "+myname+ " Rollno: "
+myroll,Toast.LENGTH_SHORT).show()
}}}

Xml

<?xml version="1.0" encoding="utf-8"?>


<AbsoluteLayout
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/getBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="209dp"
android:layout_y="404dp"
android:text="GET" />

<EditText
SYCS51 Android Development 30/01/25

android:id="@+id/rollno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="91dp"
android:layout_y="298dp"
android:ems="10"
android:hint="Roll No:"
android:inputType="textPersonName" />

<EditText
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="91dp"
android:layout_y="236dp"
android:ems="10"
android:hint="Name"
android:inputType="textPersonName" />

<Button
android:id="@+id/saveBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="95dp"
android:layout_y="404dp"
android:text="SAVE" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="109dp"
android:layout_y="145dp"
android:text="Shared Preferences"
android:textSize="20sp"
android:textStyle="bold" />

</AbsoluteLayout>

You might also like