java,android,gridview,dialog,preferencefragment
Step 1: Use an image view inside layout to store the image. image_item.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <ImageView android:id="@+id/icon_item" android:layout_width="75dp" android:layout_height="75dp" android:padding="5dp" android:layout_centerInParent="true" android:contentDescription="@string/desc_list_item_icon" android:src="@drawable/ic_img_default" /> </RelativeLayout> Step 2: Create a...
You are trying to add a PreferenceCategory with no title, which is causing the empty space. The following line is the problem: PreferenceCategory cat1 = new PreferenceCategory(root.getContext()); root.addPreference(cat1); So you can add title to your preference category like this : PreferenceCategory cat1 = new PreferenceCategory(root.getContext()); cat1.setTitle("Category"); root.addPreference(cat1); If you don't...
android,android-preferences,preferencefragment
Since it has method for registering listener: registerOnSharedPreferenceChangeListener(), you can do it via implementing SharedPreferences.OnSharedPreferenceChangeListener interface and registering prefs for changes listening, something like: @Override public void onResume() { super.onResume(); getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); } @Override public void onPause() { getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this); super.onPause();...
Settings in Overflow Menu In order to use the Settings in the overflow menu, you need to override the onOptionsItemSelected method, if not already and handle the correct id. @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_settings) { // Code to show settings. return...
java,android,oncreate,rebuild,preferencefragment
I figured it out: Like I assumed the problem was that the items always received the default values for their specific key. To overwrite this behaviour I had to call Apply() (commit would also work I guess) on the editor in the onCreate() method of my preference fragment like this:...
android,android-viewpager,appcompat,preferencefragment
You can use PreferenceFragment with getFragmentManager even if you're using ActionBarActivity (on APIs above 11 of course). But i get errors like: Type mismatch: cannot convert from AppearencePrefFragment to Fragment ... The problem is the FragmentPagerAdapter only takes either support or native implementation of fragment manager. This means you can't...
android,preferenceactivity,preferencefragment
Credit should go to njzk2 for pointing out that it was a problem with a ListPreference finding a null value. It turns out that one of the Arrays was stored as an "integer-array" instead of a "string-array". Changing that fixed the problem.
Oops. I had the wrong theme for my activity's manifest.xml file: <style name="Theme.Holo.Light.Panel"> Theme.Holo.Light.Panel makes the window floating, with a transparent background....
I am using a helper class to build EditTextPreferences, using that I can do: Context context = getActivity(); PreferenceCategory statusCat = (PreferenceCategory) findPreference(context .getString(R.string.status_category)); EditTextPreference editTextPref = EditTextPrefBuilder.getBuilder(context) .setTitle("title") .setSummary("summary") .build(); statusCat.addPreference(editTextPref); You can of course also just create the EditTextPreference without this helper class, I just find the code...
Well the problem was that in the preference.xml file the PreferenceScreen tag was fully deployed with other preferences, the ones that were supposed to be loaded with the second preference fragment. So by clicking on the PreferenceScreen, the latter was loaded with its preferences as if it was not hosted...
android,android-fragments,android-preferences,preferencefragment
Currently `PreferenceFragment' is not part of support library in Android, that's why you can't use it there, I found a library that solved that problem. You can find it here just add it to your project and you are good to go
java,android,android-fragments,preferenceactivity,preferencefragment
check if u didn't get: java.lang.RuntimeException: Subclasses of PreferenceActivity must override isValidFragment(String) to verify that the Fragment class is valid! XXX has not checked if fragment YYY is valid. isValidFragment Android API 19 when android's isValidFragment() from PreferenceActivity gets called? http://securityintelligence.com/new-vulnerability-android-framework-fragment-injection#.VRGSv1V_NBc...
android,fragment,preferencefragment
This part of the log error did not call through to super.onPause() indicates that one of your fragment(s) has the onPause method but forgot to called super.onPause(); Check your fragment's onPause does indeed call super.onPause();. Something like this. @Override public void onPause() { // code run before super super.onPause(); //...
android,android-preferences,spannablestring,edittextpreference,preferencefragment
Because it didn't appear to have anything to do with the updateAll() method, I decided to catch the IndexOutOfBounds exception, which solved the problem. @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { try { // updating and stuff } catch (IndexOutOfBoundsException e) { e.printStackTrace(); } } ...
android,android-preferences,android-support-library,android-toolbar,preferencefragment
I found the solution on my own. I used a small work-around of all this nested PreferenceScreen's. I simply made a separation to different xml-preference files, created an additional Fragment which extends PreferenceFragment and there I show an appropriate nested preference screen. Maybe somebody would found this useful. Github sources...
android,toolbar,android-actionbaractivity,preferencefragment
Move the following lines android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) getActivity().findViewById(R.id.toolbar); ((ActionBarActivity)getActivity()).setSupportActionBar(toolbar); To inside the callback Fragment#onActivityCreated(Bundle savedInstanceState). The reason is because when Fragment#onCreate(Bundle savedInstanceState) is called, the Activity wasn't instantiated yet. The method Fragment#getActivity() is probably returning null at this moment, and is guaranteed to return an Activity in...
android,android-fragments,navigation-drawer,preferencefragment
Is it possible in ActionBarActivity to remove a fragment without replacing it by another fragment ? Yes, you can use FragmentTransaction#remove(Fragment) The underlying problem however is that you are showing the PreferenceFragment with transaction.add(R.id.content_frame, prefs);. If you want only the PreferenceFragment to display wihthout the ListView behind it, you...
android,android-fragments,android-cardview,preferencefragment
The solution will be to implement ListView inside the card view. Here is the card layout : <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="8dp" card_view:cardBackgroundColor="@android:color/white" card_view:cardCornerRadius="8dp"> <ListView android:id="@android:id/list" android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="vertical" /> </android.support.v7.widget.CardView> Notice the...
android,android-fragments,slidingdrawer,preferencefragment
You are replacing PreferenceFragment in SettingsFragment's onCreateView why?? According to your code you are replacing SettingsFragment with PreferenceFragment which is static, and not destroying or removing, avoid static member functions, classes and variables in your code, because they have globally available anywhere in your code. Go through your code and...
android,xml,checkboxpreference,preferencefragment
After a few trial and error I found out that I just overloaded the Preferences. The slimmer and much cleaner version that works looks like this: <PreferenceCategory android:title="Network Service" > <CheckBoxPreference android:key="@string/communication_option" android:defaultValue="true" android:summary="Allows down- and upload." android:title="Enable server communication" /> <CheckBoxPreference android:dependency="communication_option" android:key="@string/wifi_sync_option" android:defaultValue="true" android:summary="Do...
android,android-activity,android-fragments,android-preferences,preferencefragment
I had the same issue while testing on a 1st Moto X phone. This is what I ended up doing and it works fine now: I added an empty layout to the SettingsActivity before adding the fragment. public class SettingsActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState ){ super.onCreate(savedInstanceState);...
android,dialog,listpreference,preferencefragment
So I decided that I would just implement an extended ListPreference which deals with creating the confirmation dialog and voila, It now works perfectly. public class ThemeListPreference extends ListPreference { private int mClickedDialogEntryIndex; private Context mContext; public ThemeListPreference(Context ctxt) { this(ctxt, null); } public ThemeListPreference(Context ctxt, AttributeSet attrs) { super(ctxt,...
java,android,sharedpreferences,preferenceactivity,preferencefragment
In my arrays.xml file, the entry arrays were <string-array/> and the value arrays were <integer-array/>. My solution was to make the integer arrays string arrays. That seemed to fix the problem.
android,android-fragments,preferenceactivity,preferencefragment
Add on Preference Tag in your .xml file <PreferenceCategory android:title="@string/pref_profile_setting" > <EditTextPreference android:title="@string/pref_user_name" android:summary="@string/pref_user_name_summary" android:key="prefName"/> <Preference android:title="@string/pref_select_dob" android:key="prefDob" > <ListPreference android:title="@string/pref_gender" android:summary="@string/pref_postcode_summary" android:key="prefGender" android:entries="@array/gender"...
java,android,preferencefragment,onpreferenceclicklistener
Edit: Make your SettingsFragment an inner class of PairActivity: public class PairActivity extends Activity { public class SettingsFragment extends PreferenceFragment { } } Then you can safely reference the activity with PairActivity.this. Edit: That's a nice answer you linked and it's indeed the proper way to use it like that....
android,android-fragments,listpreference,preferencefragment,onpreferenceclicklistener
Finally I have got the answer my self. array1Preference .setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { apref = (String) newValue;//Sets the new value for second list loader (LoadArray2) PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().putString(key, "0").commit();//Clear in the preference file the 2nd listpreference selection data. setArray2PreferenceData(array2Preference);//Reload data from server...