InterviewSolution
| 1. |
Design one custom view for displaying TextView in UI with a attributes tribute like Title and Colour. |
|
Answer» In your scenario, we have to DESIGN a login screen in the application where the login activity is having two control an email and a password. An email we want to display AUTOFILL data based on the user email address. We will USE AutoCompleteTextView in our layout to display email and password data. What we can do here in our Java activity we can create an object of Account Manager and we load the user accounts through the AccountManager. As some accounts MAY not have an email address linked to them, we filter them and keep only the ones who match an email regex. We also use a Set to remove the duplicates. Now we just have an array of Strings as the data source and we just bind via an ArrayAdapter the list of an email address. Now we can display data of email and password in autocomplete text view. One we need to REMEMBER before running this code we need to add below permission in our manifest file. android.permission.GET_ACCOUNTSThe layout file will look like this: <AutoCompleteTextView android:id="@+id/autoCompleteTextView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:text="Enter Email Address" />And. Activity, java file will be like this: private ArrayAdapter<String> getEmailAdapter(Context context) { Account[] accounts = AccountManager.get(context).getAccounts(); String[] addresse= new String[accounts.length]; for (int i = 0; i < accounts.length; i++) { addresses[i] = accounts[i].name; } return new ArrayAdapter<String>(context, android.R.layout.simple_dropdown_item_1line, addresses); |
|