4

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?

scatmoi
  • 1,958
  • 4
  • 18
  • 32

1 Answers1

5

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.

curioustechizen
  • 10,572
  • 10
  • 61
  • 110
  • My `onCreateDialogView()` returns what its `super.onCreateDialogView()` returns: **null**. How do I make it return non-null without changing the original ListPreference view/layout? I don't really want to change anything in the view/layout. All I really want is get a handle/reference to the original ListPreference **view**. Is this at all possible? If so, how? +1 & thanks for now. – scatmoi Jun 27 '13 at 03:40
  • There doesn't seem to be a public API to get a handle to the `ListView` that is housed within a `ListPreference`. You do have a `DialogPreference#getDialog()` - which you can cast to `AlertDialog()`, and from there you can do a `getListView()` but this depends on a lot of implementation details and I wouldn't recommend it. I'd rather suggest you to create a custom `Preference` where you have full control over the content view. – curioustechizen Jun 27 '13 at 05:42
  • Actually, see [this comment](http://stackoverflow.com/questions/17181083/how-to-attach-gesturedetector-to-a-listpreference#comment25182806_17351742), but you answered my question so well, so accepting + bounty. – scatmoi Jun 28 '13 at 00:21
  • How do you get hold of all of the dialog, and set the direction of it (for example, in order to support it being RTL ) ? – android developer May 25 '14 at 21:59