List of items + other buttons...

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

List of items + other buttons...

Postby Oeli » Wed Nov 12, 2008 1:13 am

Hi,

I want to read a list of items from the sqlite database and display them in a list on the phone. I know that this would be possible with a ListActivity. However, if I use a ListActivity, I can't display anything else than the list itself, can I?
I want a text on top of the list and on the bottom of the list a search field and a button. How is this possible with an Activity or ListActivity? After hours of researching it seems to be impossible...?

Thank in advance for any hint
Oeli
Freshman
Freshman
 
Posts: 3
Joined: Tue Nov 11, 2008 10:30 pm

Top

Postby MrSnowflake » Wed Nov 12, 2008 8:41 am

To put stuff in you ListView, you need to make a ListAdapter. To have the ListView filled with stuff from a db, you need a CursorAdapter or maybe even a custom CursorAdapter. Check the docs.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby Oeli » Wed Nov 12, 2008 11:26 am

Thanks for your reply. But unfortunately that wasn't my question at all.

* Displaying all the dynamic data from the database in a list in a Listview isn't the problem at all.

* However: The problem is that I don't want just to display the list on the display. I also want a text on top of the list and a searchfield + button at the bottom. So a view like this:

my title.. sometext...etc...
¦list entry 1 | ... ¦
¦list entry 2 | ... ¦
¦list entry 3 | ... ¦
¦.....
¦last entry | ... ¦
[input box] Search!

The problem is that as I said a ListView can only contain a single List and nothing else, can't it? (according to the api docs)

Is it somehow possible to accomplish this? Would be kinda stupid if not...
Oeli
Freshman
Freshman
 
Posts: 3
Joined: Tue Nov 11, 2008 10:30 pm

Postby MrSnowflake » Wed Nov 12, 2008 11:32 am

Oh hehe, sorry read the question wrong indeed. You ment you can't display anything but the ListView.

Ofcourse you can! ListActivity is only a wrapper class around an Activity which has a ListView.

Try a layout lik this: (using everything with the correct name and parameters)
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <linlayout>
  2.  
  3. <ListView andoid:id="@android:list" />
  4.  
  5. <TextView android:text="hello" />
  6.  
  7. </linlayout>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby Oeli » Wed Nov 12, 2008 2:28 pm

Hmm could you be a bit more specific? You mean, we need our class to extend ListActivity or does Activity suffice? Because we tried to just add some text to the Listactivity before and it didn't work. And when we change our working Activity to ListActivity it results in crashes on the emulator. But if we need a ListActivity we'll get that to work.

Thanks :)
Oeli
Freshman
Freshman
 
Posts: 3
Joined: Tue Nov 11, 2008 10:30 pm

Postby MrSnowflake » Wed Nov 12, 2008 2:44 pm

ListActivity is a wrapper class, which means, it's just an activity with some convenience funtions to access the ListView it displays. Nothing more, nothing less.

Main.xml:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.    android:orientation="vertical"
  6.  
  7.    android:layout_width="fill_parent"
  8.  
  9.    android:layout_height="fill_parent"
  10.  
  11.    >
  12.  
  13. <TextView  
  14.  
  15.    android:layout_width="fill_parent"
  16.  
  17.    android:layout_height="wrap_content"
  18.  
  19.    android:text="You textview"
  20.  
  21.    />
  22.  
  23. <ListView
  24.  
  25.         android:id="@android:id/list"
  26.  
  27.    android:layout_width="fill_parent"
  28.  
  29.    android:layout_weight="1"
  30.  
  31.    android:layout_height="wrap_content" />
  32.  
  33. <TextView  
  34.  
  35.    android:layout_width="fill_parent"
  36.  
  37.    android:layout_height="wrap_content"
  38.  
  39.    android:layout_gravity="bottom"
  40.  
  41.    android:text="Another textview but now beneath the ListView"
  42.  
  43.    />
  44.  
  45.        
  46.  
  47. </LinearLayout>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Re: List of items + other buttons...

Postby Sparkletron » Wed Nov 26, 2008 9:22 pm

Oeli wrote:I know that this would be possible with a ListActivity. However, if I use a ListActivity, I can't display anything else than the list itself, can I?


Forget ListActivity. As the moderator explained, that's just a convenience Activity that is meant to show a list (and only a list).

What you want is a regular Activity and some Layout like LinearLayout. A layout is like a smart container for all your widgets--smart because it not only holds references to your widgets but it knows how to arrange them. Add your list and anything else you want to the layout. Then set the Activity's contentView to your layout.
Sparkletron
Developer
Developer
 
Posts: 26
Joined: Tue Nov 04, 2008 6:17 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests