• 8

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Android aar failed to find ID in item layout

I have created a custom calendar viewgroup that encompasses, among other elements, a spinner to allow the user to select the year. This custom view will be used in multiple apps, so it makes sense to create something reusable like an AAR. I have some specific styling I need to do so the view looks the same no matter where I deploy it.

My custom viewgroup finds and renders the main layout of the viewgroup. But, when the user taps the year spinner and wants to change the year, the adapter can't find the text ID of the layout for the dropdown. I've checked the merged manifest in my APK and can see both the layout and the text id from my AAR, but it crashes upon tap with a error of :

java.lang.RuntimeException: Failed to find view with ID us.martypants.mycustomviewgroup:id/current_year in item layout

Interestly enough,if instead of a custom layout and textId I use android's layout (i.e. android.R.layout.simple_spiner_item and android.R.id.text1) the APK can find the resources, show the list of selections and set the result - although the styling I need is absent.

custom view:

package com.algtskr.algtskrcommon

class DropdownAgeSelectView (context: Context, attrs: AttributeSet): RelativeLayout(context, attrs),
AdapterView.OnItemSelectedListener {

private var mCounterColor = 0
private var mAge = 0

init {
        .inflate(R.layout.dropdown_ageselect_layout, this, true)

    attrs.let {
        val typedArray = context.obtainStyledAttributes(it,
            R.styleable.DropdownAgeSelectView, 0, 0)

        mCounterColor = typedArray.getColor(R.styleable.DropdownAgeSelectView_counter_color, 0)
        mAge = typedArray.getInteger(R.styleable.DropdownAgeSelectView_initial_value, 0)


    val adapter = ArrayAdapter(context,R.layout.year_layout_text,R.id.current_year, childAgeList)
    spinner.adapter = adapter
    spinner.onItemSelectedListener = this



<?xml version="1.0" encoding="utf-8"?>
<TextView  xmlns:android="http://schemas.android.com/apk/res/android"

using Android resources in this code, the APK can see the resources, but they are unstyled:

 val adapter = ArrayAdapter(context, android.R.layout.simple_spinner_item, android.R.id.text1, childAgeList)

using my custom resources in this, the APK cannot find the resource ID, current_year, although it DOES find and use the layout file and style it correctly prior to clicking on it

val adapter = ArrayAdapter(context,R.layout.year_layout_text,R.id.current_year, childAgeList)

Any idea why the AAR correctly finds and renders the overall viewgroup layout but individual pieces within the layout are not? Why are all the layouts and resources not getting found in the APK, even though the AAR shows show them in the res/ folder and in my APK the build/intermediates/res/ shows them as well.

The problem is here:


When you pass R.id.current_year to the ArrayAdapter constructor, that will be used for both the collapsed view and for each row in the popup window (the "dropdown" views). Since your dropdown layout doesn't include a view with id R.id.current_year, you crash.

Change this setDropDownViewResource() call to use your own custom layout including an R.id.current_year TextView.

  • 1
Reply Report
      • 2
    • Oh, that's such a nice catch! Couldn't figure out why it was styled well to begin with but couldn't find the textId after the dropdown is supposed to appear - cuz I told it to look elsewhere :) Thanks, Ben!