调用屏幕首选项并关闭应用程序时我的应用程序错误。
我的 MainActivity.java:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button config = (Button) findViewById(R.id.confg);
config.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Intent settingsActivity = new Intent(getBaseContext(),PreferenciaActivity.class);
}
});
}
我的 PreferenciaActivity.java:
public class PreferenciaActivity extends PreferenceActivity {
@Override
protected void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction().replace(android.R.id.content , new PreferenciaFragment()).commit();
}
public static class PreferenciaFragment extends PreferenceFragment
{
@Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.preferencias);
}
}
我的 Preferencia.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceCategory android:title="liberador" >
<CheckBoxPreference
android:key="liberar"
android:summary="Marque para liberar"
android:title="Ativar" />
<EditTextPreference
android:dependency="liberador"
android:key="codigo"
android:summary="Informe o código"
android:title="Código" />
</PreferenceCategory>
代码很简单,不知道哪里出错了。请帮忙!