Trouble with AdapterView and addView

I want the class below to display some textviews/buttons/spinners, and also a ListView containing parsed data. However the listview/adapter/addview are causing some trouble. Heres the error I'm getting:

java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView

I've a feeling its to do with my xml files, but Im not too sure. Here's my code:

public class StatisticsScreen extends ListActivity{

private List<Message> messages; 

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.statisticsscreen);

    loadFeed();

    //other textviews and listeners added
}

private void loadFeed() {

    try{
        BaseFeedParser parser = new BaseFeedParser();
        messages = parser.parse();
        List<String> titles = new ArrayList<String>(messages.size());
        for (Message msg : messages){
            titles.add(msg.getTitle());
        }
        ArrayAdapter<String> adapter = 
        new ArrayAdapter<String>(this, R.layout.xmldatarow,titles);

        this.setListAdapter(adapter);           
    } catch (Throwable t){
        Log.e("AndroidNews",t.getMessage(),t);
    }       
}

My statisticsscreen xml:

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">

<LinearLayout android:id="@+id/statsviewlayout"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@color/black">
    //other layouts/textviews/buttons added
    <include  layout="@layout/xmllayout" android:id="@+id/xmllist" />

</LinearLayout>
</ListView>

xmllayout xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <ListView android:id="@+id/xmllist" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/>
    </LinearLayout>

xmldatarow is a simple textView.

EDIT:

Ok so ive updated some of the files and I'm getting a runtime exception error:

Your content must have a ListView whose attribute is 'android.R.id.list'

here are the updated files:

class:

setContentView(R.layout.statisticsscreen);    
loadFeed();        
getListView().addHeaderView(View.inflate(this, R.layout.xmllayout, null));

private void loadFeed() {
    try{
        BaseFeedParser parser = new BaseFeedParser();
        messages = parser.parse();
        List<String> titles = new ArrayList<String>(messages.size());
        for (Message msg : messages){
            titles.add(msg.getDate());
        }
        ArrayAdapter<String> adapter = 
            new ArrayAdapter<String>(this, R.layout.xmldatarow,titles);
        this.setListAdapter(adapter);
    } catch (Throwable t){
        Log.e("AndroidNews",t.getMessage(),t);
    }       
}

My statsscreenlayout stil has all of the linearlayouts with textviews etc. and I deleted this from it:

<include  layout="@layout/xmllayout" android:id="@+id/xmllist" />

Then my other two layouts are a simple textview(xmldatarow), and a listview(xmllayout). So just to clarify, there isnt any listview or any 'include' in my statsscreenlayout.

Any advice? Thanks

7
задан Akram 13 July 2012 в 09:29
поделиться