0% found this document useful (0 votes)
24 views3 pages

Tablelayout: Lecturing Training and Assement Tricks

The document describes different ways to initialize SharedPreferences in an Android application. It explains that getPreferences() can be used to initialize SharedPreferences when using a single file for an activity, while getSharedPreferences() should be used when multiple files are needed, specifying the file name and access mode. It provides an example of initializing SharedPreferences using getSharedPreferences() with a file name and private access mode.

Uploaded by

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

Tablelayout: Lecturing Training and Assement Tricks

The document describes different ways to initialize SharedPreferences in an Android application. It explains that getPreferences() can be used to initialize SharedPreferences when using a single file for an activity, while getSharedPreferences() should be used when multiple files are needed, specifying the file name and access mode. It provides an example of initializing SharedPreferences using getSharedPreferences() with a file name and private access mode.

Uploaded by

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

Lecturing training and assement tricks

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


<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="100dp"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<TableRow android:background="#0079D6" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="UserId" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="User Name" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Location" />
</TableRow>
<TableRow android:background="#DAE8FC" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Suresh Dasari" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Hyderabad" />
</TableRow>
<TableRow android:background="#DAE8FC" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Rohini Alavala" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Guntur" />
</TableRow>
<TableRow android:background="#DAE8FC" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Trishika Dasari" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Guntur" />
</TableRow>
</TableLayout>
package com.tutlane.linearlayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

Following are the different ways to initialize the Shared Preferences in our application.

If we are using single shared preference file for our activity, then we need to initialize
the SharedPreferences object by using getPreferences() method like as shown below.

SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);


In case, if we are using multiple shared preference files, then we need to initialize
the SharedPreferences object by using getSharedPreferences() method like as shown below.

SharedPreferences sharedPref = getSharedPreferences("filename1",Context.MO


DE_PRIVATE);
Here, the name “filename1” is the preference file, which want to read the values based on our
requirements and the context mode MODE_PRIVATE, will make sure that the file can be accessed
only within our application.

You might also like