Hunt
Hunt

Reputation: 8435

Textview , Button and ListView in one layout

I want to create a layout which contains TextView , Button and ListView here is the following example

example

I have created a ListView activity now i don't know how to embed it with TextView and Buttons above

Note my ListView inflate the custom layout.

Upvotes: 0

Views: 1531

Answers (2)

Steve Prentice
Steve Prentice

Reputation: 23514

You'll use a LinearLayout with a vertical orientation:

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

    <TextView android:layout_height="wrap_content" ... />
    <Button  android:layout_height="wrap_content" ... />
    <ListView android:layout_height="0dp" android:layout_weight="1" ... />

</LinearLayout>

If you want your ListView to stretch to fill the remaining room on the screen, you use the android:layout_weight attribute as above.

Upvotes: 1

Labeeb Panampullan
Labeeb Panampullan

Reputation: 34823

you can do my extend Activity also
on you can identify your controls like this

 setContentView(R.layout.yourlayout);  
 TextView textView = (TextView) findViewById(R.id.TextView01);
 Button button= (Button ) findViewById(R.id.Button01);
 ListView listView = (ListView ) findViewById(R.id.ListView01); 

and you can set listView adapter like this

listView.setAdapter(CustomAdapeterClassObject)

Upvotes: 0

Related Questions