Android Listview with button and textbox on same activity

Hi,

Complete newbie here to Android. Im using mono android to work with Android using C#. All set up and emulator running. Im tryin to get a listview to display below 2 other controls (Button and Text box) however whatever i try is not displaying the listview. All examples i have found show a simple listview but no other controls on the activity.

Is it possible to have a listview with other controls on same activity?

I have (i think) bound the list using a listadapter and pointed it to my listview but nothing is getting displayed
Main.amxl
---------

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
>
  <LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <EditText
      android:id="@+id/TrackSearch"
      android:text="Enter Track Number Here"
      android:layout_width="380px"
      android:layout_height="80px"    
  />

    <Button
      android:id="@+id/Trackbutton"
      android:text="Track"
      android:layout_width="100px"
      android:layout_height="80px"
      android:layout_alignParentRight="True"    
  />
   

  </LinearLayout>
  
  <ListView 
     android:id="@+id/Tracklist" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"
     android:layout_centerHorizontal="@+id/TrackSearch"
        />

</LinearLayout>
--------------------------------------------------------------
Activity (C#)
-------------
protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            
            //Set our view from the "main" layout resource
           SetContentView(Resource.Layout.Main);
           ListAdapter = new ArrayAdapter<string>(this, Resource.Id.Tracklist, ListOfTracks);

static readonly string[] TrackList= new String[] {"Track1","Track2","Track3"};           
           
        }

Open in new window

wilko100Asked:
Who is Participating?
 
alexey_gusevConnect With a Mentor Commented:
ok, have a look at this one for MonoDroid: http://redth.info/2010/10/12/monodroid-custom-listadapter-for-your-listview

this sample - http://sudarmuthu.com/blog/using-arrayadapter-and-listview-in-android-applications - gives you some explanations as well (and you can ignore the statements like "This is very important because only a ListActivity will be able to display the ListView" :)), but the idea is this:

1) you inherit from ArrayAdapter and override getView() method which is called by Android to create individual item in the listview at given position
2) setAdapter() for your listview
0
 
alexey_gusevCommented:
you layout prevents listview to be shown, because of 'android:layout_height="fill_parent"' in the 1st sub-layout.

you can set layoutWeight to 1 for the listview OR set height for sub-layout as wrap_content
0
 
wilko100Author Commented:
Tried both suggestions however, still not returning anything. I then striped out all the other controls to make sure its not be being dumb and just left the list view in:

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="100px"
    android:layout_height="100px"
    android:padding="10dp"    
    android:id="@+id/Tracklist">
</ListView>

Still does not display anything. Any ideas why it want display my text list?
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
alexey_gusevCommented:
the following is didsplayed perfectly well:

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

    <EditText
      android:id="@+id/TrackSearch"
      android:text="Enter Track Number Here"
      android:layout_width="380px"
      android:layout_height="80px"    
  />

    <Button
      android:id="@+id/Trackbutton"
      android:text="Track"
      android:layout_width="100px"
      android:layout_height="80px"
      android:layout_alignParentRight="True"    
  />
   

  </LinearLayout>
  
  <ListView 
     android:id="@+id/Tracklist" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"
     android:layout_centerHorizontal="@+id/TrackSearch"
        android:layout_weight="1"/>

</LinearLayout>

Open in new window


I didn't try in Mono, but in Eclipse it is OK, so I reckon there is nothing to prevent it to be OK under Mono as well.
0
 
wilko100Author Commented:
Ah so frustrating...copied xml in but still not displaying anything. Could it be my code at fault?


 ListAdapter = new ArrayAdapter<string>(this, Resource.Id.Tracklist, ListOfTracks);

static readonly string[] ListOfTracks= new String[] {"Track1","Track2","Track3"};
0
 
alexey_gusevCommented:
erm, and where do you assign this adapter to the list? usually it is the opposite in android - ie you define and fill adapter and then set list's adapter so it can fill the items
0
 
wilko100Author Commented:
Sorry, im not sure what you mean? I have my list adapter, is there something i missed?
0
 
alexey_gusevCommented:
yes, you have your list adapter, but does your listview know about its existence?
0
 
wilko100Author Commented:

How do i do that? I thought the listadapter did that. Something like ListView = listadapter;
0
 
wilko100Author Commented:
Added this:

ListView lv = FindViewById<ListView>(Resource.Id.Tracklist);

           ListAdapter = new ArrayAdapter<string>(this, Resource.Layout.Main, countries);

           lv.Adapter = ListAdapter;

 but still empty
0
 
wilko100Author Commented:
Thanks for links. Gave me a chance to grasp the fundamentals
Cheers
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.