Re: [android-developers] layout inflator
Ok thanks. And it works now. Apparently it is calling addView from parent
view, and in case of ListView, this throws an exception.
----- Original Message -----
From: "Daniel Drozdzewski" <daniel.drozdzewski@gmail.com>
To: <android-developers@googlegroups.com>
Sent: Monday, November 08, 2010 2:40 AM
Subject: Re: [android-developers] layout inflator
Hendrik,
You should not return null out of getView.
Try finding out more info, how view recycling works in ListViews.
The right answer will depend on many details of your design.
My attempt:
In the default case (in your scenario it is everything else than view
at position 0), simply return convertView, ONLY WHEN each view in your
list is exactly the same and the contenst of all items exactly are the
same OR when you are 100% sure that you are NEVER going to recycle any
views (no view will ever too high or too low to get displayed), which
is VERY hard to be sure of.
If your list is something like:
0: TITLE
1: Item 1
2: Item 2
...
i.e. each list item has a different content, then you have to do a bit
more work in your getView(). You have to populate the view behind each
item with information specific for this view at this particular
position.
Other things to look at:
- if your items are static throughout the life of the application and
there are not too many of them, try using ScrollView.
- have a look at ListView.addHeaderView(View) method to add item(s)
with different view than the most of the items of the ListView.
Daniel
On Sun, Nov 7, 2010 at 9:57 PM, Hendrik Greving <fourhendrik@gmail.com>
wrote:
> I am implementing a ListAdapter and in getView, I am returning
>
> @Override
> public View getView(int position, View convertView, ViewGroup parent) {
> switch (position) {
> case 0:
> if (title == null) {
> title = View.inflate(mContext, R.layout.main_settings_title,
> parent);
> }
> return title;
> }
> return null;
> }
>
> inflate is throwing a UnsupportedOperationException
>
> The resource is posted below. What am I doing wrong?
>
> <?
> xml version="1.0" encoding="utf-8"?>
> <
> LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
> android:layout_width="fill_parent"
> android:layout_height="fill_parent">
> <TextView android:id="@+id/menutitle"
> android:layout_width="fill_parent"
> android:layout_height="wrap_content"
> android:background="#444444"
> android:gravity="center_horizontal|top"
> android:text="Settings"
> android:textColor="#eeeeee"
> android:textStyle="bold"
> android:shadowColor="#000000"
> android:shadowRadius="3."
> android:shadowDx="3.0"
> android:shadowDy="3.0"
> android:textSize="7pt"
> android:paddingBottom="20dip"
> android:paddingTop="20dip"/>
> </
> LinearLayout>
>
> --
> 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+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
--
Daniel Drozdzewski
--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home