androidlistpreferencedialog-preference

onBindDialogView not called - Why?


I am trying to implement a subclass of ListPreference and while its constructor is being called (upon displaying it), its overriden onBindDialogView isn't.

  public MyListPreference(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
    Log.v(TAG, "MyListPreference constructed.");
  }


  @Override
  protected void onBindDialogView(View view) {
    super.onBindDialogView(view);
    Log.v(TAG, "onBindDialogView called");    
  }

Why is this happening? What am I missing?

Update: I planted a log message in onCreateDialogView() and it is being called, too.

It is only onBindDialogView() that is not being called.

Why? What are the conditions for this callback to be invoked?


Solution

  • What does your onCreateDialogView() return? onBindDialogView() is called only if you return a non-null custom view from in there. Also, onBindDialogView() is only called when you actually show the preference. Ref: Source code of DialogPreference. In particular, see showDialog() method

    If you just return the super implementation from your onCreateDialogView(), I suspect it returns null.