If anyone is interested in the answer, then I found out that I had to override onCreateView() instead. Here is the code:
@Override protected View onCreateView(ViewGroup parent) { LinearLayout layout = new LinearLayout(getContext()); LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); TextView view = new TextView(getContext()); view.setText(textToDisplay); view.setGravity(Gravity.CENTER); view.setLayoutParams(params1); layout.setPadding(15, 5, 10, 5); layout.addView(view); return layout; } This means that I don't need the XML Fragment and I don't need to override the getView() method. Now everything works as I want it to :-) /Jay On 6 Feb., 21:17, JP <jetp...@yahoo.com> wrote: > Hi guys, > > I have created an app that also contains a preference activity, that > uses the xml/preferences.xml file. > > Apart from the regular controls, I also want to include some > explanatory text, that isn't part of any of the control summaries. > > I haven't found any good way of doing this, so I decided to create my > own preference control. This uses a layout fragment, that looks like > this > > [CODE] > <?xml version="1.0" encoding="utf-8"?> > <LinearLayout > xmlns:android="_this_should_be_a_namespace_but_no_links_allowd_http_schemas > .android.com_apk_res_android" > android:layout_width="fill_parent" > android:layout_height="fill_parent" > android:orientation="vertical"> > <TextView android:id="@+id/textView" > android:layout_width="fill_parent" > android:layout_marginLeft="@dimen/margin_l" > android:layout_marginRight="@dimen/margin_l" > android:text="@string/long_explanation" > android:layout_height="wrap_content" > android:gravity="center"></TextView> > </LinearLayout> > [/CODE] > > I have then created a java class that extends > [B]android.preference.Preference[/B] and in the contructors set: > > [CODE]this.setWidgetLayoutResource(R.layout.preferences_textview_fragment); > [/CODE] > > This works fine... only the text is too long to fit in the preference > item. The item does not grow with the amount of text I write. It stays > fixed. > > I then tried to override the getView() method like this, but that > didn't make any difference. > > [CODE]@Override > public View getView(final View convertView, final ViewGroup > parent) { > final View v = super.getView(convertView, parent); > final int height = AbsListView.LayoutParams.WRAP_CONTENT; > final int width = AbsListView.LayoutParams.FILL_PARENT; > final AbsListView.LayoutParams params = new > AbsListView.LayoutParams(height, width); > v.setLayoutParams(params ); > return v; > }[/CODE] > > Can anyone help me out here and tell me what I am doing wrong... apart > from wanting to put legal text in the preference section? > > All help is appreciated! > > Jay -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en