I found a way but i don't know if it's the one thought by the design:

override SimpleAdapter.getView() then call the super class
implementation to get the view, then do your specific stuff on it
before returning it.

Best Regards,
Zied Hamdi

On Aug 3, 12:07 pm, Zied Hamdi <[email protected]> wrote:
> Hi, Maide! Maide!
>
> I'm in trouble with selecting an item in a ListView when I use a
> SimpleAdapter with my own Item display: here's my code
>
>                 setListAdapter(categoriesAdapter);
>                 categoriesAdapter.notifyDataSetChanged();
>
>                 int count = categoriesAdapter.getCount();
>                 final ListView listView = getListView();
>                 for (int i = 0; i < count; i++) {
>                         final View view = listView.getChildAt(i);
>                         View categoryLabel = view.findViewById(R.id.category);
>                         final int index = i;
>                         categoryLabel.setOnClickListener(new 
> View.OnClickListener() {
>
>                                 @Override
>                                 public void onClick(View v) {
>                                         onListItemClick(listView, view, 
> index, /* unused */-1);
>                                 }
>
>                         });
>
>                 }
> ...
>
> The problem is that final View view = listView.getChildAt(i); returns
> null for every child: seams categoriesAdapter.notifyDataSetChanged()
> is not a sufficient call to inflate the childs immediately...
>
> What is the solution then? do I have to wait until the draw method is
> called?
>
> How is it that SimpleAdapter doesn't include a method shortcut
> getChildAt(i) ?
>
> Please, if I'm totally in the wrong direction, just notify me about
> it :-)
>
> For more details:
> my item layout is the following:
> <?xml version="1.0" encoding="utf-8"?>
> <LinearLayout android:id="@+id/categories_view_item"
> android:layout_width="fill_parent" android:layout_height="fill_parent"
>         xmlns:android="http://schemas.android.com/apk/res/android";
> android:gravity="top" android:orientation="horizontal">
>
>         <TextView android:text="err" android:id="@+id/category"
> android:layout_width="fill_parent"
> android:layout_height="wrap_content"
>                 android:layout_weight="1" 
> android:textAppearance="?android:attr/
> textAppearanceLarge" android:layout_gravity="center_vertical"></
> TextView>
>         <ImageButton android:id="@+id/more"
> android:layout_width="wrap_content"
> android:layout_height="wrap_content" style="@style/PlusButton"/>
>
> </LinearLayout>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to