Android 从DialogPreference获取对布局的引用

Android 从DialogPreference获取对布局的引用,android,android-view,android-preferences,Android,Android View,Android Preferences,我有一个首选项屏幕,其中包含一个自定义的对话框preference: <com.company.project.AboutDialog android:key="about_dialog" android:icon="@drawable/logo" android:title="About Company Project" android:summary="Version information

我有一个首选项屏幕,其中包含一个自定义的
对话框preference

<com.company.project.AboutDialog
            android:key="about_dialog"
            android:icon="@drawable/logo"
            android:title="About Company Project"
            android:summary="Version information"
            android:dialogLayout="@layout/about_dialog"
            android:negativeButtonText=""
            />

在谷歌搜索了一段时间后发现了它。我需要重写
onBindDialogView
方法:

@Override
protected void onBindDialogView(View view) {
    String packageName = getContext().getPackageName();
    try {
        ((TextView)view.findViewById(R.id.textView2))
                .setText(getContext().getPackageManager().getPackageInfo(packageName, 0).versionName);
    } catch (PackageManager.NameNotFoundException e) {
        Log.w("Project", "Couldn't find version name information for about dialog");
        e.printStackTrace();
    }
    super.onBindDialogView(view);
}
@Override
protected void onBindDialogView(View view) {
    String packageName = getContext().getPackageName();
    try {
        ((TextView)view.findViewById(R.id.textView2))
                .setText(getContext().getPackageManager().getPackageInfo(packageName, 0).versionName);
    } catch (PackageManager.NameNotFoundException e) {
        Log.w("Project", "Couldn't find version name information for about dialog");
        e.printStackTrace();
    }
    super.onBindDialogView(view);
}