diiiz_
diiiz_

Reputation: 617

ImageView returning null

I have an ExpandableListView and an adapter for that.

I try to inflate a childview here:

LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.list_child, parent, false);

TextView txtListChild = (TextView) rowView.findViewById(R.id.child_header);
ImageView imgListChild = (ImageView) rowView.findViewById(R.id.child_icon);

But the ImageView is always null. I don't know why.

The textView works properly but I can't apply a Bitmap to the ImageView.

EDIT: I get a NullPointerException when apppying a bitmap.

Here is my layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:padding="9dip"
    android:layout_margin="5dip"
    android:background="@drawable/card_ui">

    <ImageView
        android:id="@+id/child_icon"
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="6dip"/>
    <TextView
        android:id="@+id/child_header"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_alignWithParentIfMissing="true"
        android:layout_toRightOf="@id/child_icon"
        android:gravity="center_vertical"/>

</RelativeLayout>

Please help!

EDIT: Here is my code. I apply the Image and Text in the getView method of my ExpandableListAdapter. I have two groups in my ExpandableListView. When I press the upper one it shows the child items. When I press the lower one it immeditely throws the NPE.

Upvotes: 0

Views: 107

Answers (1)

a person
a person

Reputation: 986

I think you need to inflate the parent (RelativeLayout), but there's a lot of missing info.

Upvotes: 1

Related Questions