1

i have a layout contains from two sections , the first section (without scroll) is for letters, the second section (with scroll) is for objects, how to put a list view on the second section? and have i make setcontentfiew(R.layout.menu) on the oncreate()? this is the activity

public class FoodsMenu extends ListActivity {

    String foods[];

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, foods));
    }

}

this is the layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:fillViewport="true" >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#000000"
            android:orientation="vertical" >
        </LinearLayout>
    </ScrollView>
    <LinearLayout
        android:layout_width="40dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="#ffffff"
        android:orientation="vertical" >
        <TextView
            android:id="@+id/tvA"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="13dp"
            android:layout_gravity="center"
            android:textColor="#025f7c"
            android:text="A" />
        <TextView
            android:id="@+id/tvB"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="13dp"
            android:layout_gravity="center"
            android:textColor="#025f7c"
            android:text="B" />
        <TextView
            android:id="@+id/tvC"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="13dp"
            android:layout_gravity="center"
            android:textColor="#025f7c"
            android:text="C" />
        <TextView
            android:id="@+id/tvD"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="13dp"
            android:layout_gravity="center"
            android:textColor="#025f7c"
            android:text="D" /> 
    </LinearLayout>
</LinearLayout>
user user
  • 2,122
  • 6
  • 19
  • 24

1 Answers1

1

The following xml will create a layout with two horizontal sections. The first section will have a vertical LinearLayout with the 5 TextViews and no scroll, while the second section will have a ListView to hold the objects.

Also note that ListView has it's own Scroller, so you don't need to add one yourself.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
    <LinearLayout
        android:layout_width="40dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="#ffffff"
        android:orientation="vertical" >
        <TextView
            android:id="@+id/tvA"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="13dp"
            android:layout_gravity="center"
            android:textColor="#025f7c"
            android:text="A" />
        <TextView
            android:id="@+id/tvB"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="13dp"
            android:layout_gravity="center"
            android:textColor="#025f7c"
            android:text="B" />
        <TextView
            android:id="@+id/tvC"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="13dp"
            android:layout_gravity="center"
            android:textColor="#025f7c"
            android:text="C" />
        <TextView
            android:id="@+id/tvD"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="13dp"
            android:layout_gravity="center"
            android:textColor="#025f7c"
            android:text="D" /> 
    </LinearLayout>
    <ListView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            ...... // other ListView attributes
          >
    </ListView>


</LinearLayout>
Swayam
  • 16,294
  • 14
  • 64
  • 102
  • why u delete the scroll? and on java activity what should i do ? – user user Jan 20 '13 at 16:05
  • The ListView has it's own Scroller. And no need to use a ListActivity. You can just use a normal activity. – Swayam Jan 20 '13 at 16:07
  • and now my java class can inheret from Activity not from listactivity right? – user user Jan 20 '13 at 16:09
  • 1
    Yes, you can use a simple activity instead of using the ListActivity. Have a look at this if you are unclear. http://stackoverflow.com/questions/6698731/listview-without-listactivity – Swayam Jan 20 '13 at 16:11