archive-com.com » COM » T » TECHOTOPIA.COM

Total: 1018

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • Creating an Android Tabbed Interface using the TabLayout Component - Techotopia
    android layout width match parent android layout height match parent android fitsSystemWindows true tools context TabLayoutDemoActivity android support design widget AppBarLayout android layout height wrap content android layout width match parent android theme style AppTheme AppBarOverlay android support v7 widget Toolbar android id id toolbar android layout width match parent android layout height attr actionBarSize android background attr colorPrimary app popupTheme style AppTheme PopupOverlay android support design widget TabLayout android id id tab layout android layout width match parent android layout height wrap content app tabMode fixed app tabGravity fill android support design widget AppBarLayout android support v4 view ViewPager android id id pager android layout width match parent android layout height match parent app layout behavior string appbar scrolling view behavior include layout layout content tab layout demo android support design widget FloatingActionButton android id id fab android layout width wrap content android layout height wrap content android layout gravity bottom end android layout margin dimen fab margin android src android drawable ic dialog email android support design widget CoordinatorLayout Creating the Pager Adapter This example will use the ViewPager approach to handling the fragments assigned to the TabLayout tabs With the ViewPager added to the layout resource file a new class which subclasses FragmentPagerAdapter now needs to be added to the project to manage the fragments that will be displayed when the tab items are selected by the user Add a new class to the project by right clicking on the com ebookfrenzy tablayoutdemo entry in the Project tool window and selecting the New Java Class menu option In the new class dialog enter TabPagerAdapter into the Name field and click OK Edit the TabPagerAdapter java file so that it reads as follows eBookFrenzy com Purchase the full edition of this Android Studio Development Essentials Android 6 Edition Book in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters package com ebookfrenzy tablayoutdemo import android support v4 app Fragment import android support v4 app FragmentManager import android support v4 app FragmentPagerAdapter public class TabPagerAdapter extends FragmentPagerAdapter int tabCount public TabPagerAdapter FragmentManager fm int numberOfTabs super fm this tabCount numberOfTabs Override public Fragment getItem int position switch position case 0 Tab1Fragment tab1 new Tab1Fragment return tab1 case 1 Tab2Fragment tab2 new Tab2Fragment return tab2 case 2 Tab3Fragment tab3 new Tab3Fragment return tab3 case 3 Tab4Fragment tab4 new Tab4Fragment return tab4 default return null Override public int getCount return tabCount The class is declared as extending the FragmentPagerAdapter class and a constructor is implemented allowing the number of pages required to be passed to the class when an instance is created The getItem method will be called when a specific page is required A switch statement is used to identify the page number being requested and to return a corresponding fragment instance Finally the getCount method simply returns the count value passed through when the object instance was created Performing the Initialization Tasks The

    Original URL path: http://www.techotopia.com/index.php/Creating_an_Android_Tabbed_Interface_using_the_TabLayout_Component (2016-02-13)
    Open archived version from archive


  • Working with the Android RecyclerView and CardView Widgets - Techotopia
    between the RecyclerView instance and the data that is to be displayed to the user The adapter is created as a subclass of the RecyclerView Adapter class and must at a minimum implement the following methods which will be called at various points by the RecyclerView object to which the adapter is assigned getItemCount This method must return a count of the number of items that are to be displayed in the list onCreateViewHolder This method creates and returns a ViewHolder object initialized with the view that is to be used to display the data This view is typically created by inflating the XML layout file onBindViewHolder This method is passed the ViewHolder object created by the onCreateViewHolder method together with an integer value indicating the list item that is about to be displayed Contained within the ViewHolder object is the layout assigned by the onCreateViewHolder method It is the responsibility of the onBindViewHolder method to populate the views in the layout with the text and graphics corresponding to the specified item and to return the object to the RecyclerView where it will be presented to the user Adding a RecyclerView to a layout is simply a matter of adding the appropriate element to the XML layout file of the activity in which it is to appear For example xml version 1 0 encoding utf 8 android support design widget CoordinatorLayout xmlns android http schemas android com apk res android xmlns app http schemas android com apk res auto xmlns tools http schemas android com tools android layout width match parent android layout height match parent android fitsSystemWindows true tools context CardStuffActivity android support v7 widget RecyclerView android id id recycler view android layout width match parent android layout height match parent app layout behavior string appbar scrolling view behavior android support design widget AppBarLayout android layout height wrap content android layout width match parent android theme style AppTheme AppBarOverlay android support v7 widget Toolbar android id id toolbar android layout width match parent android layout height attr actionBarSize android background attr colorPrimary app popupTheme style AppTheme PopupOverlay android support design widget AppBarLayout In the above example the RecyclerView has been embedded into the CoordinatorLayout of a main activity layout file along with the AppBar and Toolbar This provides some additional features such as configuring the Toolbar and AppBar to scroll off the screen when the user scrolls up within the RecyclerView a topic covered in more detail in the chapter entitled Working with the AppBar and Collapsing Toolbar Layouts eBookFrenzy com Purchase the full edition of this Android Studio Development Essentials Android 6 Edition Book in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters An Overview of the CardView google ADSDAQBOX FLOW google The CardView class is a user interface view that allows information to be presented in groups using a card metaphor Cards are usually presented in lists using a RecyclerView

    Original URL path: http://www.techotopia.com/index.php/Working_with_the_Android_RecyclerView_and_CardView_Widgets (2016-02-13)
    Open archived version from archive

  • An Android RecyclerView and CardView Tutorial - Techotopia
    Book in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters Edit the new RecyclerAdapter java file to add some import directives and to declare that the class now extends RecyclerView Adapter Rather than create a separate class to provide the data to be displayed some basic arrays will also be added to the adapter to act as the data for the app package com ebookfrenzy carddemo import android support v7 widget RecyclerView import android util Log import android view LayoutInflater import android view View import android view ViewGroup import android widget ImageView import android widget TextView import java util ArrayList public class RecyclerAdapter extends RecyclerView Adapter RecyclerAdapter ViewHolder private String titles Chapter One Chapter Two Chapter Three Chapter Four Chapter Five Chapter Six Chapter Seven Chapter Eight private String details Item one details Item two details Item three details Item four details Item file details Item six details Item seven details Item eight details private int images R drawable android image 1 R drawable android image 2 R drawable android image 3 R drawable android image 4 R drawable android image 5 R drawable android image 6 R drawable android image 7 R drawable android image 8 Within the RecyclerAdapter class we now need our own implementation of the ViewHolder class configured to reference the view elements in the card layout xml file Remaining within the RecyclerAdapter java file implement this class as follows public class RecyclerAdapter extends RecyclerView Adapter RecyclerAdapter ViewHolder class ViewHolder extends RecyclerView ViewHolder public ImageView itemImage public TextView itemTitle public TextView itemDetail public ViewHolder View itemView super itemView itemImage ImageView itemView findViewById R id item image itemTitle TextView itemView findViewById R id item title itemDetail TextView itemView findViewById R id item detail The ViewHolder class contains an ImageView and two TextView variables together with a constructor method that initializes those variables with references to the three view items in the card layout xml file The next item to be added to the RecyclerAdapter java file is the implementation of the onCreateViewHolder method Override public ViewHolder onCreateViewHolder ViewGroup viewGroup int i View v LayoutInflater from viewGroup getContext inflate R layout card layout viewGroup false ViewHolder viewHolder new ViewHolder v return viewHolder This method will be called by the RecyclerView to obtain a ViewHolder object It inflates the view hierarchy card layout xml file and creates an instance of our ViewHolder class initialized with the view hierarchy before returning it to the RecyclerView The purpose of the onBindViewHolder method is to populate the view hierarchy within the ViewHolder object with the data to be displayed It is passed the ViewHolder object and an integer value indicating the list item that is to be displayed This method should now be added using the item number as an index into the data arrays This data is then displayed on the layout views using the references created in the constructor method of the ViewHolder

    Original URL path: http://www.techotopia.com/index.php/An_Android_RecyclerView_and_CardView_Tutorial (2016-02-13)
    Open archived version from archive

  • Working with the Android AppBar and Collapsing Toolbar Layouts - Techotopia
    not expand from the collapsed state until the downward scrolling motion reaches the limit of the list If the minHeight property is set the view will appear during the initial scrolling motion but only until the minimum height is reached It will then remain at that height and will not expand fully until the top of the list is reached Note this option only works when used in conjunction with both the enterAlways and scroll options For example app layout scrollFlags scroll enterAlways enterAlwaysCollapsed android minHeight 20dp exitUntilCollapsed When set the view will collapse during an upward scrolling motion until the minHeight threshold is met at which point it will remain at that height until the scroll direction changes For the purposes of this example the scroll and enterAlways options will be set on the Toolbar as follows android support v7 widget Toolbar android id id toolbar android layout width match parent android layout height attr actionBarSize android background attr colorPrimary app popupTheme style AppTheme PopupOverlay app layout scrollFlags scroll enterAlways With the appropriate properties set run the app once again and make an upward scrolling motion in the RecyclerView list This should cause the toolbar to collapse out of view Figure 34 5 A downward scrolling motion should cause the toolbar to re appear Figure 34 5 Introducing the Collapsing Toolbar Layout The CollapsingToolbarLayout container enhances the standard toolbar by providing a greater range of options and level of control over the collapsing of the app bar and its children in response to coordinated scrolling actions The CollapsingToolbarLayout class is intended to be added as a child of the AppBarLayout and provides features such as automatically adjusting the font size of the toolbar title as the toolbar collapses and expands A parallax mode allows designated content in the app bar to fade from view as it collapses while a pin mode allows elements of the app bar to remain in fixed position during the contraction A scrim option is also available to designate the color to which the toolbar should transition during the collapse sequence eBookFrenzy com Purchase the full edition of this Android Studio Development Essentials Android 6 Edition Book in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters To see these features in action the app bar contained in the activity card demo xml file will be modified to use the CollapsingToolbarLayout class together with the addition of an ImageView to better demonstrate the effect of parallax mode The new view hierarchy that makes use of the CollapsingToolbarLayout is represented by the diagram in Figure 34 6 Figure 34 6 Load the activity card demo xml file into the Designer tool in Text mode and modify the layout so that it reads as follows xml version 1 0 encoding utf 8 android support design widget CoordinatorLayout xmlns android http schemas android com apk res android xmlns app http schemas android

    Original URL path: http://www.techotopia.com/index.php/Working_with_the_Android_AppBar_and_Collapsing_Toolbar_Layouts (2016-02-13)
    Open archived version from archive

  • Implementing an Android Navigation Drawer - Techotopia
    within the navigation drawer and is passed as an argument a reference to the selected menu item which can be used to extract and identify the selected item id Override public boolean onNavigationItemSelected MenuItem item Handle navigation view item clicks here int id item getItemId if id R id nav camera else if id R id nav gallery else if id R id nav slideshow else if id R id nav manage else if id R id nav share else if id R id nav send DrawerLayout drawer DrawerLayout findViewById R id drawer layout drawer closeDrawer GravityCompat START return true If it is appropriate to do so and as outlined in the above example it is also important to close the drawer after the item has been selected eBookFrenzy com Purchase the full edition of this Android Studio Development Essentials Android 6 Edition Book in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters Using the Navigation Drawer Activity Template While it is possible to implement a navigation drawer within any activity the easiest approach is to select the Navigation Drawer Activity template when creating a new project or adding a new activity to an existing project Figure 35 2 This template creates all of the components and requirements necessary to implement a navigation drawer requiring only that the default settings be adjusted where necessary Creating the Navigation Drawer Template Project Create a new project in Android Studio entering NavDrawerDemo into the Application name field and ebookfrenzy com as the Company Domain setting before clicking on the Next button On the form factors screen enable the Phone and Tablet option and set the minimum SDK setting to API 8 Android 2 2 Froyo Continue to proceed through the screens requesting the creation of a Navigation Drawer Activity named NavDrawerActivity with a corresponding layout file named activity nav drawer Click on the Finish button to initiate the project creation process The Template Layout Resource Files Once the project has been created it will contain the following XML resource files located under app res layout in the Project tool window activity nav drawer xml This is the top level layout resource file It contains the DrawerLayout container and the NavigationView child The NavigationView declaration in this file indicates that the layout for the drawer header is contained within the nav header nav drawer xml file and that the menu options for the drawer are located in the activity nav drawer drawer xml file In addition it includes a reference to the app bar nav drawer xml file app bar nav drawer xml This layout resource file is included by the activity nav drawer xml file and is the standard app bar layout file built within a CoordinatorLayout container as covered in the preceding chapters As with previous examples this file also contains a directive to include the content file which in this case is named content

    Original URL path: http://www.techotopia.com/index.php/Implementing_an_Android_Navigation_Drawer (2016-02-13)
    Open archived version from archive

  • An Android Studio Master/Detail Flow Tutorial - Android 6 - Techotopia
    detail content defined in the item detail xml and item DetailFragment java files item detail xml The layout file that accompanies the item DetailFragment class and contains the layout for the content area of the detail pane By default this contains a single TextView object but may be changed to meet your specific application needs In single pane mode this fragment is loaded into the layout defined by the activity item detail xml file In two pane mode this layout is loaded into the FrameLayout area of the item list xml w900dp file so that it appears adjacent to the master list item DetailFragment java The fragment class file responsible for displaying the item detail xml layout and populating it with the content to be displayed in the detail pane This fragment is initialized and displayed within the item DetailActivity java file to provide the content displayed within the activity item detail xml layout for single pane mode and the item list xml w900dp layout for two pane mode DummyContent java A class file intended to provide sample data for the template This class can either be modified to meet application needs or replaced entirely By default the content provided by this class simply consists of a number of string items Modifying the Master Detail Flow Template While the structure of the Master Detail Flow template can appear confusing at first the concepts will become clearer as the default template is modified in the remainder of this chapter As will become evident much of the functionality provided by the template can remain unchanged for many master detail implementation requirements In the rest of this chapter the MasterDetailFlow project will be modified such that the master list displays a list of web site names and the detail pane altered to contain a WebView object instead of the current TextView When a web site is selected by the user the corresponding web page will subsequently load and display in the detail pane Changing the Content Model The content for the example as it currently stands is defined by the DummyContent class file Begin therefore by selecting the DummyContent java file located in the Project tool window in the app java com ebookfrenzy masterdetailflow dummy folder and reviewing the code At the bottom of the file is a declaration for a class named DummyItem which is currently able to store two String objects representing a content string and an ID The updated project on the other hand will need each item object to contain an ID string a string for the web site name and a string for the corresponding URL of the web site To add these features modify the DummyItem class so that it reads as follows public static class DummyItem public String id public String website name public String website url public DummyItem String id String website name String website url this id id this website name website name this website url website url Override public String toString return website

    Original URL path: http://www.techotopia.com/index.php/An_Android_Studio_Master/Detail_Flow_Tutorial_-_Android_6 (2016-02-13)
    Open archived version from archive

  • An Overview of Android 6 Intents - Techotopia
    it is essential that those activities be listed in the application manifest file The following AndroidManifest xml contents are correctly configured for an application containing activities named ActivityA and ActivityB xml version 1 0 encoding utf 8 manifest xmlns android http schemas android com apk res android package com ebookfrenzy intent1 intent1 application android icon mipmap ic launcher android label string app name activity android label string app name android name com ebookfrenzy intent1 intent1 ActivityA intent filter action android name android intent action MAIN category android name android intent category LAUNCHER intent filter activity activity android name ActivityB android label ActivityB activity application manifest Returning Data from an Activity As the example in the previous section stands while data is transferred to ActivityB there is no way for data to be returned to the first activity which we will call ActivityA This can however be achieved by launching ActivityB as a sub activity of ActivityA An activity is started as a sub activity by starting the intent with a call to the startActivityForResult method instead of using startActivity In addition to the intent object this method is also passed a request code value which can be used to identify the return data when the sub activity returns For example startActivityForResult i REQUEST CODE In order to return data to the parent activity the sub activity must implement the finish method the purpose of which is to create a new intent object containing the data to be returned and then calling the setResult method of the enclosing activity passing through a result code and the intent containing the return data The result code is typically RESULT OK or RESULT CANCELED but may also be a custom value subject to the requirements of the developer In the event that a sub activity crashes the parent activity will receive a RESULT CANCELED result code The following code for example illustrates the code for a typical sub activity finish method public void finish Intent data new Intent data putExtra returnString1 Message to parent activity setResult RESULT OK data super finish In order to obtain and extract the returned data the parent activity must implement the onActivityResult method for example protected void onActivityResult int requestCode int resultCode Intent data String returnString if resultCode RESULT OK requestCode REQUEST CODE if data hasExtra returnString1 returnString data getExtras getString returnString1 Note that the above method checks the returned request code value to make sure that it matches that passed through to the startActivityForResult method When starting multiple sub activities it is especially important to use the request code to track which activity is currently returning results since all will call the same onActivityResult method on exit Implicit Intents Unlike explicit intents which reference the Java class name of the activity to be launched implicit intents identify the activity to be launched by specifying the action to be performed and the type of data to be handled by the receiving activity For example an action type of ACTION

    Original URL path: http://www.techotopia.com/index.php/An_Overview_of_Android_6_Intents (2016-02-13)
    Open archived version from archive

  • Android 6 Explicit Intents – A Worked Example - Techotopia
    35dp android text Large Text android textAppearance android attr textAppearanceLarge EditText android id id editText1 android layout width 300dp android layout height wrap content android layout below id textView1 android layout centerHorizontal true android layout marginTop 66dp android ems 10 android inputType text RelativeLayout eBookFrenzy com Purchase the full edition of this Android Studio Development Essentials Android 6 Edition Book in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters If designing the layout using the Designer tool in Design mode note that the onClick property on the button view has been configured to call a method named onClick the width of the EditText view has been set to 300dp and the views have been assigned IDs button1 TextView1 and editText1 The completed layout should resemble that illustrated in Figure 38 3 Figure 38 3 Reviewing the Application Manifest File In order for ActivityA to be able to launch ActivityB using an intent it is necessary that an entry for ActivityB be present in the AndroidManifest xml file Locate this file within the Project tool window app manifests double click on it to load it into the editor and verify that Android Studio has automatically added an entry for the activity xml version 1 0 encoding utf 8 manifest xmlns android http schemas android com apk res android package com ebookfrenzy explicitintent application android allowBackup true android icon mipmap ic launcher android label string app name android supportsRtl true android theme style AppTheme activity android name ActivityA intent filter action android name android intent action MAIN category android name android intent category LAUNCHER intent filter activity activity android name ActivityB activity application manifest With the second activity created and listed in the manifest file it is now time to write some code in the ActivityA class to issue the intent Creating the Intent The objective for ActivityA is to create and start an intent when the user touches the Ask Question button As part of the intent creation process the question string entered by the user into the EditText view will be added to the intent object as a key value pair When the user interface layout was created for ActivityA the button object was configured to call a method named onClick when clicked by the user This method now needs to be added to the ActivityA class ActivityA java source file as follows package com ebookfrenzy explicitintent import android support v7 app AppCompatActivity import android os Bundle import android content Intent import android view View import android widget EditText import android widget TextView public class ActivityA extends AppCompatActivity Override protected void onCreate Bundle savedInstanceState super onCreate savedInstanceState setContentView R layout activity a public void onClick View view Intent i new Intent this ActivityB class final EditText editText1 EditText findViewById R id editText1 String myString editText1 getText toString i putExtra qString myString startActivity i The code for the onClick method follows the techniques outlined

    Original URL path: http://www.techotopia.com/index.php/Android_6_Explicit_Intents_%E2%80%93_A_Worked_Example (2016-02-13)
    Open archived version from archive



  •