displaying large contentberaldi/macc_18/05bis.pdf · displaying long content: listactivity • it...

14
DISPLAYING LARGE CONTENT Roberto Beraldi

Upload: others

Post on 27-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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