在我的应用程序获取视图我有一个PreferenceScreen它看起来像这样:从定制偏好
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<CheckBoxPreference
android:key="state"
android:title="@string/stateTitle"
android:summary="@string/stateSummary"
android:defaultValue="false" />
<Preference
android:key="test"
android:layout="@layout/pref_control"
android:dependency="state" />
</PreferenceScreen>
现在的问题是如何才能得到这是在我的pref_control.xml
从PreferenceActivity的意见?我尝试了正常的findViewById()
,但以NullPointerException结束。这里是我的代码,导致异常:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
((Button) findViewById(R.id.startTime)).setText("bla");
((Button) findViewById(R.id.endTime)).setText("bla");
}
当然,我知道但我在测试偏好中使用自定义布局。在这个布局是一个按钮,我想要得到这个按钮,但是在'Preference'对象中,我没有一个名为'findViewById()'或其他的方法。 – Cilenco
哦,我看到了,我想这是你使用findViewById的时候。我一直认为,只要是在夸大了布局后就应该没问题。 –
我认为你应该发布实际导致异常的代码 –