Get view of preference with custom layout

后端 未结 1 1034
情深已故
情深已故 2021-02-14 00:46

I have a preference android:layout gft. I\'ve set the layout in the android:layout property of the preference in the xml file.

Now I need to do an initialization of a bu

1条回答
  •  情书的邮戳
    2021-02-14 01:05

    You need to create a class that extends Preference, then override onBindView and you'll have access to the view.

    public class MyPreference extends Preference {
    
        ...
    
        @Override
        protected void onBindView(View view) {
            super.onBindView(view);
            View myView = (View) view.findViewById(R.id.my_id);
            // ... do stuff
        }
    
    }
    

    You'll probably have to override some more methods, read about custom preference in PreferenceActivity - http://developer.android.com/guide/topics/ui/settings.html

    0 讨论(0)
提交回复
热议问题