I have a screen where you can enable/disable modules for my Android application.
For this I use a CheckboxPreference screen. This is all good, but the summary field gets
Hmn had the same problem today. My alternative solution is to just allow to display more Text within the summary.
Just create your own subclass of CheckBoxPreference that looks something like this:
public class CheckBoxPreferenceWithLongSummary extends CheckBoxPreference{
public CheckBoxPreferenceWithLongSummary(Context context) {
super(context);
}
public CheckBoxPreferenceWithLongSummary(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CheckBoxPreferenceWithLongSummary(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
TextView summaryView = (TextView) view.findViewById(android.R.id.summary);
summaryView.setMaxLines(10);
}
}
Then within your PreferenceScreen (i assume you use xml to set up the Preference layout - not sure if its even possible completely programmatically) just replace the old <CheckBoxPreference.../>
with your new implementation like <com.example.whatever.CheckBoxPreferenceWithLongSummary ... />
Seems to work just fine for me, altough i'm not sure about the findViewById(android.R.id.summary) because in the parentClass com.android.internal.R.id.summary is used which seems to be not directly accessible from within Java? Hope its not just an coincidence :)
You might be able to create your own subclass of CheckboxPreference
that gives you more room.
I found an alternative solution that fits better in my case since I needed longer summaries for different types of preferences, not only CheckboxPreferences.
data/res/layout/preference.xml
from the SDK to res/layout/preference_long_summary.xml
in my app. (I took the one from API level 7, since it seems to work also for higher levels)android:maxLines
attribute from the @+android:id/summary
TextViewandroid:layout="@layout/preference_long_summary"