1.

Take the scenario where we have two applications from the same package like Gmail and Google Calendar.  This app can share data with each other for example Gmail meeting mail will save in Google calendar. Now how we will make sure the data cannot be used by some other third party application. How you will secure your data?

Answer»

When we need to create any custom VIEW in Android, we will EXTEND our class from the View parent class. In this scenario, as we need to create a custom Text view so we will create a subclass of TextView class.  And then we can our Custom textview in a layout.xml file.

For example please follow below code where I am trying to create Custom TextView

CustomTextView extends TextView { private String title;     private boolean COLOR; title = tarry.getString(R.styleable.CustomTextView_settitle);             if(title == null)             setText("Custom Message");             else                 setText("Welcome to the Class"); color = tarry.getBoolean(R.styleable. CustomTextView _setColor, false);             if(color == true)             setTextColor(Color.RED); }

We need to define our custom textview  in \res\layout  folder and write the code LIKE as shown below.

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:orientation="vertical"> <com.example.CustomTextView     android:layout_width="wrap_content"     android:layout_height="wrap_content"     app:settitle="Welcome"     app:setColor="true"     android:layout_marginTop="200dp"     android:layout_marginLeft="120dp"     android:textStyle="bold"     android:textSize="18dp"/> </LinearLayout>


Discussion

No Comment Found

Related InterviewSolutions