I created a Setting activity in my app, but it didn't work.
This is my SettingFragment
class:
public class SettingFragment extends PreferenceFragmentCompat
{
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey)
{
setPreferencesFromResource(R.xml.pref, rootKey);
}
}
This is my SettingActivity
:
public class SettingActivity extends AppCompatActivity
{
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content, new SettingFragment())
.commit();
}
}
This is MainActivity
. Clicking the button will open SettingActivity
.
btn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
Intent intent = new Intent(MainActivity.this, SettingActivity.class);
startActivity(intent);
}
});
And this is Preference.xml
:
<PreferenceScreen
xmlns:app="http://schemas.android.com/apk/res-auto">
<Preference
app:key="feedback"
app:title="Send feedback"
app:summary="Report technical issues or suggest new features"/>
</PreferenceScreen>
What is the R.id.content
? It was used in the developer.android site example.
What is the problem? How can I solve this?