androidpreferencesummary

Android preference summary . How to set 3 lines in summary?


Summary of preference is allowed only 2 lines . If I want to display 3 lines or more in summary . How can I do ?


Solution

  • You can create you Preference class by extending any existing preference:

    public class LongSummaryCheckboxPreference extends CheckboxPreference
    {
        public LongSummaryCheckboxPreference(Context ctx, AttributeSet attrs, int defStyle)
        {
            super(ctx, attrs, defStyle);        
        }
    
        public LongSummaryCheckboxPreference(Context ctx, AttributeSet attrs)
        {
            super(ctx, attrs);  
        }
    
        @Override
        protected void onBindView(View view)
        {       
            super.onBindView(view);
    
            TextView summary= (TextView)view.findViewById(android.R.id.summary);
            summary.setMaxLines(3);
        }       
    }
    

    And then in preferences.xml:

     <com.your.package.name.LongSummaryCheckBoxPreference 
        android:key="@string/key"
        android:title="@string/title"
        android:summary="@string/summary" 
        ... />
    

    The drawback is that you need to subclass all preference types you need 3 lines summary for.