prgDevelop
prgDevelop

Reputation: 1587

Android - Is there a way to put a ListView along with other controls within the same activity?

I want to create a ListView and a few other text boxes for filtering the list. Is there a way to make it happen using one activity (i.e at the same page)?

One more question: May I modify a ListView directly without creating a ListActivity? and how do I make the ListView in my ListActivity visible? (how do I link it with the xml?).

Upvotes: 0

Views: 761

Answers (3)

waqaslam
waqaslam

Reputation: 68177

Yes, you can have ListView together with some other required views with in the same Activity. The way I would do this is to define an Activity and add ListView (with width and height set to fill_parent) and add a SlidingDrawer which contains all the options required to alter ListView. With this approach, your ListView will take up all the space on screen and offering user to interact freely. However, on the other hand, SlidingDrawer will give give extra space for all the list altering views/options.

Upvotes: 1

Phix
Phix

Reputation: 9890

Yes. ListActivity seems to cause a lot of confusion for people, when all it is, is a regular activity with a ListView as the content, some helper methods, and that's it.

To add your own, create a new layout file and add all the widgets you need like you would any other layout file. Example:

<LinearLayout xmlns:android="http://schemas.android.com/res/apk/android"
    android:weightSum="1.0"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/whatever"
        android:layout_weight="0" />
    <ListView
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1" />
</LinearLayout>

Upvotes: 2

Argyle
Argyle

Reputation: 3394

You certainly can create a layout which contains both a ListView and other controls! Make your Activity have a layout which contains both your ListView and your other controls.

<RelativeLayout>
    <ListView android:id="@+id/listy"/>

    <Button android:id="@+id/buttony"
            android:layout_below="@id/listy"/>

</RelativeLayout>

In your Activity, you'll still need to hook up your data adapter to the ListView and so forth.

Upvotes: 1

Related Questions