> For the complete documentation index, see [llms.txt](https://codandotv.gitbook.io/craftd/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://codandotv.gitbook.io/craftd/how-to-use/android/view-system.md).

# View System

### 1. Add in a xml that you want to use

```xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />

</androidx.constraintlayout.widget.ConstraintLayout>

```

### 2. Add in your ViewModel the interface from the Dynamic

```kotlin
class YourViewModel(
    val craft: CraftDView,
    val repository: DynamicRepository 
) : ViewModel() {
 //Stuffs 
}
```

### 3. In your Activity/Fragment connect the Dynamic to the adapter in xml

```kotlin
  override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityDynamicComponentBinding.inflate(layoutInflater)
        setContentView(binding.root)

        binding.recycler.adapter = vm.craft as CraftDViewAdapter
        //--- Stuffs
}
```

### 4. Create object `Properties` of according with your components for example:

```
@JsonIgnoreProperties(ignoreUnknown = true)
data class TextProperties(
    @JsonProperty("xxx") val myProperties1: String,
    @JsonProperty("xxx") val myProperties2: String,
)
```

### 5. Create object `ViewRenders` of according with your components for example:

```kotlin
class MyComponentRender(override var onClickListener: CraftDViewListener?)
    : ViewRenderer<MyComponentRender.MyHolder>("Your Key", "Your Identifier") {

    inner class MyHolder(val anyView: AnyView) : RecyclerView.ViewHolder(anyView)

    override fun bindView(model: SimpleProperties, holder: MyHolder, position: Int) {
        val anyProperties = model.value.convertToVO<AnyProperties>()

        holder.any.text = anyProperties.text
        anyProperties.textColorHex?.let { textColorHex ->
            //Stuff
        }
        anyProperties.actionProperties?.let { actionProperties ->
          //Stuff
        }
    }

    override fun createViewHolder(parent: ViewGroup): MyHolder {
        return MyHolder(AnyView(parent.context))
    }
}
```

### 6. Configure your ViewModel to accept for example:

```kotlin
class DynamicViewModel(
    val craft: CraftD,
    val repository: SampleCraftDRepository
) : ViewModel() {
  
    fun onResume() {
        viewModelScope.launch {
            repository.getDynamic()
                .catch {
                    it.printStackTrace()
                }
                .collect {
                    setupDynamicRender(it)
                    craft.setViewObjectDiff(it)
                }
        }
    }

    private fun setupDynamicRender(list: List<SimpleProperties>) {
        craft.registerRenderers(
            CraftDBuilderManager.getBuilderRenders(
                simpleProperties = list,
                customDynamicBuilderList = customListViewRender // Can you pass your custom list from ViewRender
            ) { action ->
                listener.invoke(action)
            })
    }

    private val listener = object : CraftDViewListener {
        override fun invoke(actionProperties: ActionProperties) {
            actionProperties.analytics?.let {
               //Stuff
            }
            actionProperties.deeplink?.let {
                //Stuff
            }
        }
    }
}
```

### 7. Enjoy and Have fun to create a json that you need

Your json must to have at least two parameters `key` and `value` that are respective of your object for example:

```json
{
  "data": [
    {
      "key": "MyDynamicView",
      "value": {
        "text": "Any",
        "textColor": "Any"
      }
    }
  ]
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://codandotv.gitbook.io/craftd/how-to-use/android/view-system.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
