Android的观点得到了preference在preferenceActivity得到了、观点、Android、preference

由网友(念旧不代表我想回到过去ㄟ)分享简介:我想获得用于在显示特定preference查看例如我preferenceActivity,这样我就可以修改它的属性,例如:I would like to get View instance that is used to display specific Preference in my PreferenceAc...

我想获得用于在显示特定preference查看例如我 preferenceActivity,这样我就可以修改它的属性,例如:

I would like to get View instance that is used to display specific Preference in my PreferenceActivity, so i can modify its properties, for example:

public class SettingsActivity extends PreferenceActivity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        addPreferencesFromResource(R.xml.preference);
        Preference pref = findPreference("key");
        pref.getView().setVisibility(View.GONE);
            //not necessarily setVisibility, i hope you get my point
    }
}

我只发现这个方法: getView (查看convertView,ViewGroup中父)。但似乎混乱给我,说如果我想查看我的preference,需提供本人观点和ViewGroup中作为参数??

I only found this method: getView (View convertView, ViewGroup parent). But it seems confusing to me, that if i want to get View of my preference, i need to provide view and viewGroup as parameters??

有人能解释如何使用这种方法,或点我到另一种方法来从我的preference实例得到查看。

Could someone explain how to use this method, or point me to another method to get View from my Preference instance.

PS:如果可能的话,我宁愿不延长preference类,但我不如有必要介意

PS: if possible, i would rather NOT extend Preference class, but i dont mind it if necessary

推荐答案

我不知道如何获取视图为preference,但如果你想从屏幕(设置可见,除去视图View.gone),可以使用下列内容:

I'm not sure on how to get the view for a preference, but if you want to remove the view from the screen (set visibility to View.gone) you can use the following:

获取preferenceScreen()。删除preference(在preference)

getPreferenceScreen().removePreference(thePreference)

阅读全文

相关推荐

最新文章