tags:

views:

38

answers:

1

Hi,

I defined a layout like this:

<LinearLayout>
  <ListView />
</LinearLayout>

and I want to use a wrapper class for it:

public class MyView extends LinearLayout {
    ListView mListView;

    public build() {
        mListView = (ListView)findViewById(R.id.mylistview);
    }
}

not sure how to inflate this from my layout file:

MyView v = LayoutInflater.from(this).inflate(R.layout.myview, null);

the inflater of course does not know what 'MyView' type is, and returns only View. What's a good way to reconcile this?

Thanks

A: 

Why do you inflate LinearLayout in linear layout ? What you probably need, define a layout for myView. Inflate it in some sort of initialize procedure ( for that view ). And than you'll use your new view in xml layout. More on that here http://developer.android.com/guide/topics/ui/custom-components.html

Alex Volovoy