DISPLAYING LARGE CONTENTberaldi/MACC_18/05Bis.pdf · Displaying long content: ListActivity • It...
Transcript of DISPLAYING LARGE CONTENTberaldi/MACC_18/05Bis.pdf · Displaying long content: ListActivity • It...
![Page 1: DISPLAYING LARGE CONTENTberaldi/MACC_18/05Bis.pdf · Displaying long content: ListActivity • It is an subclass of Activity • There is no layout to inflate • Allows to display](https://reader036.fdocuments.net/reader036/viewer/2022080718/5f78cb54b40ab4205c2ea4f9/html5/thumbnails/1.jpg)
DISPLAYING LARGE CONTENTRoberto Beraldi
![Page 2: DISPLAYING LARGE CONTENTberaldi/MACC_18/05Bis.pdf · Displaying long content: ListActivity • It is an subclass of Activity • There is no layout to inflate • Allows to display](https://reader036.fdocuments.net/reader036/viewer/2022080718/5f78cb54b40ab4205c2ea4f9/html5/thumbnails/2.jpg)
Displaying long content• The screen size of a device is limited, so many times to
show all the content at once is unfeasible• This is a common issue and android provides special
classes and layouts to deal with this problem• There are different solutions (older�new):• ListActivity• ListView• GridView• CardView• RecyclerView
![Page 3: DISPLAYING LARGE CONTENTberaldi/MACC_18/05Bis.pdf · Displaying long content: ListActivity • It is an subclass of Activity • There is no layout to inflate • Allows to display](https://reader036.fdocuments.net/reader036/viewer/2022080718/5f78cb54b40ab4205c2ea4f9/html5/thumbnails/3.jpg)
Displaying long content: ListActivity• It is an subclass of Activity• There is no layout to inflate• Allows to display an array of items, that are ‘clickable’• An ‘ArrayAdapter’ is required to transform an item (data) into a view
• A predefined layout is used to create the view • By default, the array adapter creates a view by calling toString() on each data object
in the provided collection, and places the result in a TextView.
• Warning: Action bar is not displayed
![Page 4: DISPLAYING LARGE CONTENTberaldi/MACC_18/05Bis.pdf · Displaying long content: ListActivity • It is an subclass of Activity • There is no layout to inflate • Allows to display](https://reader036.fdocuments.net/reader036/viewer/2022080718/5f78cb54b40ab4205c2ea4f9/html5/thumbnails/4.jpg)
ListActivity (example)
![Page 5: DISPLAYING LARGE CONTENTberaldi/MACC_18/05Bis.pdf · Displaying long content: ListActivity • It is an subclass of Activity • There is no layout to inflate • Allows to display](https://reader036.fdocuments.net/reader036/viewer/2022080718/5f78cb54b40ab4205c2ea4f9/html5/thumbnails/5.jpg)
Displaying long content: listView andGridView• Uses a special layout (named listView or gridView)• Similar to ListActivity, but can extend AppCompatActivity
![Page 6: DISPLAYING LARGE CONTENTberaldi/MACC_18/05Bis.pdf · Displaying long content: ListActivity • It is an subclass of Activity • There is no layout to inflate • Allows to display](https://reader036.fdocuments.net/reader036/viewer/2022080718/5f78cb54b40ab4205c2ea4f9/html5/thumbnails/6.jpg)
ListActivity, ListView, GridView compared
![Page 7: DISPLAYING LARGE CONTENTberaldi/MACC_18/05Bis.pdf · Displaying long content: ListActivity • It is an subclass of Activity • There is no layout to inflate • Allows to display](https://reader036.fdocuments.net/reader036/viewer/2022080718/5f78cb54b40ab4205c2ea4f9/html5/thumbnails/7.jpg)
Displaying long content: recyclerView• Is ‘faster’ and more flexible• Uses a recyclerView layout• It automatically ‘recycles’ views as they are no longer
visible (more efficient than others)• It requires a LayoutManager to manage views
• (for example the scrolling can be done horizontally)
• It requires an Adapter to create a single View and update data of the View• Allows ‘animations’ (e.g., it pushes the toolbar out of the
screen)
![Page 8: DISPLAYING LARGE CONTENTberaldi/MACC_18/05Bis.pdf · Displaying long content: ListActivity • It is an subclass of Activity • There is no layout to inflate • Allows to display](https://reader036.fdocuments.net/reader036/viewer/2022080718/5f78cb54b40ab4205c2ea4f9/html5/thumbnails/8.jpg)
Displaying long content: recyclerView
![Page 9: DISPLAYING LARGE CONTENTberaldi/MACC_18/05Bis.pdf · Displaying long content: ListActivity • It is an subclass of Activity • There is no layout to inflate • Allows to display](https://reader036.fdocuments.net/reader036/viewer/2022080718/5f78cb54b40ab4205c2ea4f9/html5/thumbnails/9.jpg)
Recycler view and (collapsing) toolbar
![Page 10: DISPLAYING LARGE CONTENTberaldi/MACC_18/05Bis.pdf · Displaying long content: ListActivity • It is an subclass of Activity • There is no layout to inflate • Allows to display](https://reader036.fdocuments.net/reader036/viewer/2022080718/5f78cb54b40ab4205c2ea4f9/html5/thumbnails/10.jpg)
Example
![Page 11: DISPLAYING LARGE CONTENTberaldi/MACC_18/05Bis.pdf · Displaying long content: ListActivity • It is an subclass of Activity • There is no layout to inflate • Allows to display](https://reader036.fdocuments.net/reader036/viewer/2022080718/5f78cb54b40ab4205c2ea4f9/html5/thumbnails/11.jpg)
CardView• CardView extends the FrameLayout class and show
information inside cards• CardView widgets can have shadows and rounded
corners.
![Page 12: DISPLAYING LARGE CONTENTberaldi/MACC_18/05Bis.pdf · Displaying long content: ListActivity • It is an subclass of Activity • There is no layout to inflate • Allows to display](https://reader036.fdocuments.net/reader036/viewer/2022080718/5f78cb54b40ab4205c2ea4f9/html5/thumbnails/12.jpg)
Spinner• Like a menu, it shows a set of options• It requires an adapter
![Page 13: DISPLAYING LARGE CONTENTberaldi/MACC_18/05Bis.pdf · Displaying long content: ListActivity • It is an subclass of Activity • There is no layout to inflate • Allows to display](https://reader036.fdocuments.net/reader036/viewer/2022080718/5f78cb54b40ab4205c2ea4f9/html5/thumbnails/13.jpg)
List an device rotation• As after a device rotation the activity is re-created, it could
be required to store the ‘state’ of the list (i.e., which is the first item visible)
• Methods exit to get/set the first item to be shown
![Page 14: DISPLAYING LARGE CONTENTberaldi/MACC_18/05Bis.pdf · Displaying long content: ListActivity • It is an subclass of Activity • There is no layout to inflate • Allows to display](https://reader036.fdocuments.net/reader036/viewer/2022080718/5f78cb54b40ab4205c2ea4f9/html5/thumbnails/14.jpg)
Fetching data from the network• If data source is remotely located on a network, it is worth
to use an additional thread to fetch data asynchronously• The adapter is notified when data are available• For long query, a page based solution must be used
HTTPClient
AsyncTask…
Adapter ListView
notifyDataChange
LocalData
Source
stor
eda
ta
getView
ViewdataHTTP/JSON