[mono-android] Adding a listview to a tabview

Paul Johnson paul at all-the-johnsons.co.uk
Sat Feb 18 01:10:31 UTC 2012


Hi,

I'm trying to re-use the same view for a number of different sets of
data by using a list view, but this is being held within a tabview
layout.

I've got by tabview code working fine (I've lifted it from another
application of mine), have adapted the layout to include the new
listview widget and added the code from the Xamarin listview example
into my Strings.xml file.

Problem comes in two ways. Firstly, you can't have both
Activity1:TabActivity,ListActivity (two base types). Secondly is
altering the content depending on the list item selected

The way I had it planned was like this

(code)
            string[] countries =
Resources.GetStringArray(Resource.Array.countries_array);
            SetListAdapter(new ArrayAdapter<string>(this,
Resource.Layout.Main, countries));

This would be used to set up the view - but this obviously won't work
(I've tried using Android.Widget.ListView but SetListAdapter doesn't
reside there, neither is it IListAdapter.

Would I be better off calling another Activity class (this time set as
ListActivity) and on return the app continues and initialises the
tabviews? Second to that, if I do call the ListActivity from the
TabActivity, is there a simple way to keep track of which set of
options needs to be displayed?

For example

View 1 listview item 3 -> View 2 listview item4 -> View 3 listview
(item 3 on view 1 could be CDs by Falco, so view 2 would be the CDs,
item 1 on view 1 could be DVDs staring Tim Curry with view 2 being the
titles and so on)

If I include a backbutton image, then hitting that on View 3 takes you
back to view 2 then view 1.

Thanks

Paul


More information about the Monodroid mailing list