0

My ListView is currently stuck in a little small view-box on the bottom of my screen. When it's clicked, I want it to expand to some height. I've read guides on here on how to do that, but nothing seems to work. Here's my code here.

    list.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Log.v("Miles", "Listview clicked");
            LayoutParams adapterParams = (LayoutParams) parent.getLayoutParams();
            adapterParams.height = 400;
            parent.setLayoutParams(adapterParams);
        }   
    });

And the layout that this code snippet is happening in:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="tribeTimes.EventFragment"
android:focusable="true"
android:focusableInTouchMode="true" >

<TextView
    android:id="@+id/event"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

   <TextView
       android:background="@drawable/buttonborder_selector"
        android:id="@+id/likes"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/event"
        android:layout_marginBottom="20dp"
        android:clickable="true"
        android:gravity="center"
        android:textAppearance="?android:attr/textAppearanceMedium" />

   <EditText
       android:background="@drawable/buttonborder_selector"
       android:hint="@string/yourComment"
       android:id="@+id/yourComment"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_below="@id/likes"
       android:layout_marginBottom="20dp"
       android:gravity="left"
       android:inputType="text" >
       <requestFocus/>
    </EditText>

    <ListView
        android:layout_below="@id/yourComment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/listInParent" >
    </ListView>

</RelativeLayout>
Miles Peele
  • 325
  • 5
  • 15

2 Answers2

1

As your ListView is "stuck in a little small view-box", and you have its height set to wrap_content, I'm not sure if you've only a couple of items in it, or if you've set the height some other way. As such, I've set the ListView's initial height to 100dp for the example. I'm sure you'll need to adjust some things.

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="tribeTimes.EventFragment"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:focusable="true"
    android:focusableInTouchMode="true" >

    <LinearLayout
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_alignParentTop="true" >

        <TextView
            android:id="@+id/event"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView       
            android:id="@+id/likes"
            android:background="@drawable/buttonborder_selector"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:clickable="true"
            android:gravity="center"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/yourComment"
            android:background="@drawable/buttonborder_selector"
            android:hint="@string/yourComment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:gravity="left"
            android:inputType="text" >
            <requestFocus/>
        </EditText>

    </LinearLayout>

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:id="@+id/listInParent" >
    </ListView>

</RelativeLayout>

Then, when resizing the ListView, you'll need to add a layout rule to the parameters before setting them.

RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(list.getWidth(), 400);
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
list.setLayoutParams(lp);
Mike M.
  • 38,532
  • 8
  • 99
  • 95
0

For some reason, list.setLayoutParams(new RelativeLayout.LayoutParams(400, 600)) worked to change the height of the listview itself. Now the problem is the other views aren't accordingly resized; as in, they don't collapse when the listview is made bigger.

Miles Peele
  • 325
  • 5
  • 15