Hello!

I'm trying to write my own custom ListAdapter. In getView() I want to 
inflate the views from an XML file. To do this I have the following code:

    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(ctx);
        TextView view = (TextView)inflater.inflate(R.layout.notes_row, 
parent);
        view.setText(data[position]);
        return view;
    }

However I get an exception in the call to inflate():

E/AndroidRuntime(  209): java.lang.UnsupportedOperationException: 
addView(View, LayoutParams) is not supported in AdapterView
E/AndroidRuntime(  209): at 
android.widget.AdapterView.addView(AdapterView.java:461)
E/AndroidRuntime(  209): at 
android.view.LayoutInflater.inflate(LayoutInflater.java:415)
E/AndroidRuntime(  209): at 
android.view.LayoutInflater.inflate(LayoutInflater.java:320)
E/AndroidRuntime(  209): at 
android.view.LayoutInflater.inflate(LayoutInflater.java:276)
E/AndroidRuntime(  209): at 
com.github.simplenotes.MyAdapter.getView(MyAdapter.java:59)

I guess that this means that addView is not supported int the parent object 
sent to getView(). I just want to double check that I'm not supposed to try 
to attach my views to the parent ViewGroup in this case. If that is the 
case, won't I loose out on inheriting layout parameter and such if I use a 
call like this?

        TextView view = (TextView)inflater.inflate(R.layout.notes_row, 
null);

Basically, what is the correct way to inflate views in a ListAdapter?

:.:: mattias

-- 
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

Reply via email to