Stefan van de Laarschot
Stefan van de Laarschot

Reputation: 2163

Android Listview is not scrolling still not working

Good day!

I have tried a lot of other posts on stackoverflow but it didn't work for me, maybe its because I'm new to Android Development.

My problem is as follow:

enter image description here

XML Layout:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_detail_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >

<TextView
    android:layout_width="match_parent"
    android:layout_height="89dp"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="Medium Text"
    android:id="@+id/txtDetails"
    android:layout_gravity="center_horizontal|top"
    android:padding="5dp" />

<ListView
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="369dp"
    android:layout_gravity="center_horizontal|bottom" />

</FrameLayout>

Preview in Android Studio:

enter image description here

inside the onCreateView:

 public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) { }

Binding the listview:

 public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
 final View rootView = inflater.inflate(R.layout.fragment_item_detail,     container, false);


  List<Events> list = Events.getEvents();
  int max = list.size();
  String[] Values = new String[max];
  for (int i = 0; i < max; i++) {

      Events e = list.get(i);
      Values[i] = e.getNaam();
  }

  ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
                                    rootView.getContext(),
                                    android.R.layout.simple_list_item_1, Values);

 listView.setAdapter(arrayAdapter);

 return rootview;

 }

Another point is i can't click a list item wich is strange !

Any ideas or tips? what do i wrong?

Kind Regards, Stefan

Upvotes: 3

Views: 2688

Answers (4)

Roel Strolenberg
Roel Strolenberg

Reputation: 2950

<LinearLayout>    
    <ScrollView>
         <ListView ...>

         </listView>
    </ScrollView>
</LinearLayout>

You need to add a LinearLayout around the scrollview, that way the scrollview knows inside what it should scroll. If this doesn't work, replace the ListView with another LinearLayout and add your items to the LinearLayout. I'm not sure if a View is capable of scrolling at all. Try first option first, otherwise try the latter. I know the latter will work for sure since I used the exact same design myself in an app I'm developing.

Upvotes: 1

Mauker
Mauker

Reputation: 11487

Try something like the following.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/item_detail_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    tools:context=".ItemDetailActivity"
    tools:ignore="MergeRootFrame" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:id="@+id/linearLayout">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Medium Text"
            android:id="@+id/txtDetails"
            android:layout_gravity="center_horizontal|top"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:paddingTop="10dp"
            android:paddingBottom="10dp" />

        <ListView
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
    </LinearLayout>

</FrameLayout>

Upvotes: 2

Salah Nour ElDin
Salah Nour ElDin

Reputation: 508

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_detail_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="Medium Text"
    android:id="@+id/txtDetails"
    android:layout_gravity="center_horizontal|top"
    android:padding="5dp" />

<ListView
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal|bottom" />

</FrameLayout>

Upvotes: 2

rogi1609
rogi1609

Reputation: 438

As already mentioned in the comment, you have to add a ScrollView around your ListView, e.g.:

<ScrollView>
     <ListView ....>
     </ListView>
</ScrollView>

Upvotes: -2

Related Questions