# List

If you need to display scrolling elements dynamically, you should check if they are lists or [grids](https://learn.mondayhero.io/design-to-swift/creating-components/system-components/broken-reference). Lists are vertical, and grids can be vertical or horizontal. In lists, only 1 cell can be in a column but for Grids, it can be more than 1 cell in a column. Here is an example of both of them:

![Lists and Grids](https://479678609-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MEfkN8oSQyQ4BaBzwxH%2F-MKpDF6Xgwb_Z7dwqXur%2F-MKpE6OolHScNdfLNTPX%2Flists%20and%20grids.png?alt=media\&token=b789979e-27f8-43d8-88a7-a80c1792cec9)

This page is created for lists.&#x20;

If you need to display scrolling elements dynamically, you should check if they are lists or [grids](https://learn.mondayhero.io/design-to-swift/creating-components/system-components/broken-reference). You can find [how to understand the difference here](https://learn.mondayhero.io/design-to-swift/creating-components/system-components/broken-reference). If you have decided that you want to create lists, this is the right place to read.

An example of a list is below. In the image, the cell prototype repeats itself with different data inside.&#x20;

Lists are called different names in iOS and Android. They are explained below with the code and details.&#x20;

![List Example.](https://479678609-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MEfkN8oSQyQ4BaBzwxH%2F-MS36IByj9NhkNkmEyns%2F-MS3KwH_gZJZLAEIy45F%2FlistView-design-to-code.png?alt=media\&token=20882f83-f03f-4c31-a48e-9e9a5a6d286c)

![List creation GIF.](https://479678609-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MEfkN8oSQyQ4BaBzwxH%2F-MT-NklPruWUNAc5HnfU%2F-MT-NrdwIR5cMsJCdQuv%2Flist-gif.gif?alt=media\&token=ebfd5f23-0c04-47c8-9caa-66072aa05b19)

### Generated code for iOS/Android and Details

{% tabs %}
{% tab title="iOS" %}

## TableView

Lists are called in`TableView` Swift language. With `TableView`, you can view a group that aligns all children in a single direction. In`TableView`, no matter how wide they are, the vertical list has only one child per row, and your list will only be the one-row height(Height of the tallest child + padding).

`CellPrototype`wraps a layout and will often be the container used in a layout for each item within a `TableView`. Let's check the generated code.

TableView is added to the page's View Controller file.&#x20;

{% code title="ListPageViewController.swift " %}

```swift
import UIKit

class ListPageViewController: UIViewController {

//Connection from an Interface Builder to a UI component
@IBOutlet private weak var explorePostsTableView: UITableView!

	override func viewDidLoad() {
		super.viewDidLoad()
		setupViews()
	}
}

extension ListPageViewController {
	private func setupViews() {
	
		//TableView properties
		self.explorePostsTableView.rowHeight = UITableView.automaticDimension
		self.explorePostsTableView.estimatedRowHeight = 30
		self.explorePostsTableView.dataSource = self	

	}
	
}		

// MARK: - Table View DataSource

extension ListPageViewController: UITableViewDataSource {
	func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
		return 1
	}

	func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
		let cell = tableView.dequeueReusableCell(withIdentifier: "ExplorePostTableViewCell") as! ExplorePostTableViewCell
		return cell
	}
}
```

{% endcode %}

The Cell is added as a separate file.&#x20;

{% code title="ExplorePostsTableViewCell.swift" %}

```swift

import UIKit
import SnapKit

class ExplorePost: UITableViewCell {
	
	// MARK: - Properties
	@IBOutlet private weak var photoImageView2: UIImageView!
	@IBOutlet private weak var rosieDelLabel: UILabel!
	@IBOutlet private weak var likesLabel: UILabel!
	@IBOutlet private weak var heartLikedImageView: UIImageView!

	override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
		super.init(style: style, reuseIdentifier: reuseIdentifier)
		self.setupViews()
	}

	required init?(coder aDecoder: NSCoder) {
		super.init(coder: aDecoder)
	}

	func setupViews() {
		
		rosieDelLabel.text = NSLocalizedString("rosie.del", comment: "")
		rosieDelLabel.textColor = UIColor.porpoise
		rosieDelLabel.numberOfLines = 0
		rosieDelLabel.font = UIFont.textStyle2
		rosieDelLabel.textAlignment = .left

		likesLabel.text = NSLocalizedString(".likes2", comment: "")
		likesLabel.textColor = UIColor.anchor2
		likesLabel.numberOfLines = 0
		likesLabel.font = UIFont.textStyle6
		likesLabel.textAlignment = .right

	}
}
```

{% endcode %}
{% endtab %}

{% tab title="Android" %}

## RecyclerView-LinearLayoutManager

{% hint style="warning" %}
⚠️This feature is available in **only Mac App**. Web App **support for Android** is coming soon.\
If you need to install the desktop app, [click here.](https://learn.mondayhero.io/getting-started/install-app-and-plugin)
{% endhint %}

In Android lists are used with `RecyclerView`and`LinearLayout`. The repetitive cells are `CardView`&#x20;

With `LinearLayout`, you can view a group that aligns all children in a single direction. In`LinearLayout`, no matter how wide they are, the vertical list has only one child per row, and your list will only be the one-row height(Height of the tallest child + padding).

![Android RecyclerView and CardView](https://479678609-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MEfkN8oSQyQ4BaBzwxH%2F-MHFANrCOC6gc2K7q24z%2F-MHFQG7NhUfspOqdnQSq%2Fimage.png?alt=media\&token=157242b8-3443-40ce-9101-1ac3ff968014)

`CardView` wraps a layout and will often be the container used in a layout for each item within a `RecyclerView`. Let's check the generated code.

```markup
<!--activityListPage.xml-->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/explorePicturesRecyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/layout_explore_post_card_view"
android:layout_marginStart="20dp"
android:layout_marginEnd="19dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/popularTextView"
app:layout_constraintBottom_toBottomOf="parent"/>
```

```markup
<!--LayoutExplorePhotoCardView.xml-->
<androidx.cardview.widget.CardView
	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="wrap_content">
	
	<androidx.constraintlayout.widget.ConstraintLayout
	android:layout_width="match_parent"
	android:layout_height="wrap_content">
	
	<ImageView
	android:id="@+id/photoImageView"
	android:layout_width="0dp"
	android:layout_height="wrap_content"
	android:src="@drawable/photo"
	android:scaleType="centerCrop"
	android:layout_marginEnd="0dp"
	android:layout_marginBottom="13dp"
	app:layout_constraintStart_toStartOf="parent"
	app:layout_constraintEnd_toEndOf="parent"
	app:layout_constraintTop_toTopOf="parent"
	app:layout_constraintBottom_toTopOf="@+id/rosieDelTextView"/>
	
	<TextView
	android:id="@+id/rosieDelTextView"
	android:layout_width="0dp"
	android:layout_height="wrap_content"
	android:text="@string/rosie_del"
	style="@style/textStyle2"
	android:textAlignment="textStart"
	android:textColor="?attr/porpoise"
	android:layout_marginEnd="8dp"
	app:layout_constraintStart_toStartOf="parent"
	app:layout_constraintEnd_toStartOf="@+id/likesTextView"
	app:layout_constraintTop_toBottomOf="@+id/photoImageView"
	app:layout_constraintBottom_toBottomOf="parent"/>
	
	<TextView
	android:id="@+id/likesTextView"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:text="@string/_likes"
	style="@style/textStyle6"
	android:textAlignment="textEnd"
	android:textColor="?attr/anchor2"
	android:layout_marginEnd="8dp"
	android:layout_marginTop="13dp"
	app:layout_constraintStart_toEndOf="@+id/rosieDelTextView"
	app:layout_constraintEnd_toStartOf="@+id/heartLikedImageView"
	app:layout_constraintTop_toBottomOf="@+id/photoImageView"
	app:layout_constraintBottom_toBottomOf="parent"/>
	
	<ImageView
	android:id="@+id/heartLikedImageView"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:src="@drawable/heartliked"
	android:layout_marginTop="14dp"
	android:layout_marginBottom="1dp"
	app:layout_constraintStart_toEndOf="@+id/likesTextView"
	app:layout_constraintEnd_toEndOf="parent"
	app:layout_constraintTop_toBottomOf="@+id/photoImageView"
	app:layout_constraintBottom_toBottomOf="parent"/>
	
	</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
```

{% endtab %}
{% endtabs %}
