I want some text images / buttons / spinners, as well as a ListView containing the parsed data, to be displayed in the class below. However, listview / adapter / addview cause certain problems. Here is the error I get:
java.lang.UnsupportedOperationException: addView (View, LayoutParams) is not supported in AdapterView
I feel this is related to my xml files, but Im not too sure. Here is 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();
My xml screen statistics:
<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 text file.
EDIT:
Ok, so I updated some files, and I get an exception exception at runtime:
Your content should 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 linear schedules with text images, etc., and I removed this from it:
<include layout="@layout/xmllayout" android:id="@+id/xmllist" />
Then my other two layouts are plain text view (xmldatarow) and listview (xmllayout). So, just to clarify, there is no list or any include in my statsscreenlayout.
Any tips? Thanks