PreferenceFragment
'u kullanan hesap ayarları sayfasındaki ana sayfamdan Activity
numaralı sayfaya gidiyorum.Bir Etkinlikten TercihYoluna Nasıl Gidilir?
Bu öğeyi navigasyon çekmecesi üzerinden gerçekleştirmeye çalışıyorum, ürün tıklandığında ayarlar sayfası görüntülenmelidir. Diğer tüm sayfalarım, hesap ayarları sayfası hariç tüm Fragment
ve hepsi düzgün çalışıyor (ayarlar sayfası hariç). PreferenceFragment
'un Fragment
'dan çıktığını düşündüm, bu yüzden işe yarayacak mı?
O MainPage.java bana aşağıdaki hatayı verecek
public class AccountSettings extends PreferenceFragment {
Activity mActivity;
private static final String ARG_SECTION_NUMBER = "section_number";
public static AccountSettings newInstance(int sectionNumber) {
AccountSettings fragment = new AccountSettings();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //inflating layout
addPreferencesFromResource(R.xml.settings);
setHasOptionsMenu(true);
restoreActionBar();
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mActivity = activity;
}
public void restoreActionBar() {
ActionBar actionBar = ((AppCompatActivity)getActivity()).getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle("Account Settings");
}
public AccountSettings() {
}
}
MainPage.java
@Override
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
if (position == 0) {
fragmentManager.beginTransaction()
.replace(R.id.container, PlaceholderFragment.newInstance(1))
.commit();
} else if (position == 1) {
fragmentManager.beginTransaction()
.replace(R.id.container, Search.newInstance(2))
.commit();
}
else if (position == 2) {
fragmentManager.beginTransaction()
.replace(R.id.container, Favourites.newInstance(3))
.commit();
}
else if (position == 3) {
fragmentManager.beginTransaction()
.replace(R.id.container, History.newInstance(4))
.commit();
}
else if (position == 4) {
fragmentManager.beginTransaction()
.replace(R.id.container, AccountSettings.newInstance(5))
.commit();
}
}
AccountSettings.java:
'replace(int, android.support.v4.app.Fragment)' in 'android.support.v4.app.FragmentTransaction' cannot be applied to '(int, com.example.laptop.whatsfordinner.AccountSettings)'
Bir Fragment
'a değiştirmeyi denedim ve işe yarıyor ama ben PreferenceFragment
kullanmak istiyorum, nasıl çalıştırabilirim?
Şüphesiz, gerçekten çok açık bir şey eksik miyim?
Bir seçenek, bu durum için oluşturulan [PreferenceFragmentCompat] (http://developer.android.com/reference/android/support/v7/preference/PreferenceFragmentCompat.html) kullanmak olacaktır. Örnek için buraya bakın: http://stackoverflow.com/questions/32487206/inner-preferencescreen-not-opens-with-preferencefragmentcompat –