Skip to main content
Glama

android_generate_list_adapter

Generate Android RecyclerView adapters and layouts for DHIS2-style lists with options for shimmer placeholders, pull-to-refresh, and sticky headers.

Instructions

Generate Android RecyclerView adapter and layout for DHIS2-style lists

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
adapterNameNoAdapter class name
itemLayoutNoViewBinding layout base name (e.g., item_data_element)
shimmerNoInclude shimmer placeholder pattern
pullToRefreshNoInclude pull-to-refresh pattern
stickyHeadersNoInclude sticky headers in list

Implementation Reference

  • Handler for the android_generate_list_adapter tool. Extracts arguments and calls generateAndroidListAdapter to produce Android RecyclerView adapter code.
    case 'android_generate_list_adapter':
      const aListArgs = args as any;
      const aList = generateAndroidListAdapter(aListArgs);
      return { content: [{ type: 'text', text: aList }] };
  • Core implementation function that generates Kotlin RecyclerView Adapter code and corresponding XML layout for Android list display.
    export function generateAndroidListAdapter(args: any): string {
      const { adapterName = 'DataElementAdapter', itemLayout = 'item_data_element' } = args;
    
      return `# Android RecyclerView Adapter: ${adapterName}
    
    ## Adapter (Kotlin)
    \`\`\`kotlin
    class ${adapterName}(private val items: MutableList<DataElement>) : RecyclerView.Adapter<${adapterName}.ViewHolder>() {
    
        class ViewHolder(val binding: ${camelToPascal(itemLayout)}Binding) : RecyclerView.ViewHolder(binding.root)
    
        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
            val inflater = LayoutInflater.from(parent.context)
            val binding = ${camelToPascal(itemLayout)}Binding.inflate(inflater, parent, false)
            return ViewHolder(binding)
        }
    
        override fun onBindViewHolder(holder: ViewHolder, position: Int) {
            val item = items[position]
            holder.binding.name.text = item.displayName
            holder.binding.type.text = item.valueType
        }
    
        override fun getItemCount(): Int = items.size
    }
    \`\`\`
    
    ## Item Layout (XML)
    \`\`\`xml
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="16dp">
    
        <TextView android:id="@+id/name" android:layout_width="match_parent" android:layout_height="wrap_content" android:textStyle="bold"/>
        <TextView android:id="@+id/type" android:layout_width="match_parent" android:layout_height="wrap_content"/>
    </LinearLayout>
    \`\`\`
    `;
  • Tool permission registration mapping android_generate_list_adapter to 'canUseMobileFeatures' permission check.
      ['android_generate_material_form', 'canUseMobileFeatures'],
      ['android_generate_list_adapter', 'canUseMobileFeatures'],
      ['android_generate_navigation_drawer', 'canUseMobileFeatures'],
      ['android_generate_bottom_sheet', 'canUseMobileFeatures'],
    ]);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Dradebo/dhis2-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server