Android Listview not scrolling until it works
Good day!
I've tried many other posts on stackoverflow but it didn't work for me, possibly because I'm new to android development.
My problem is as follows:
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>
Android Studio Preview :
inside onCreateView:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { }
Linking a list:
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;
}
One more point: I cannot click the list item, which is weird!
Any ideas or advice? what am I wrong?
Regards, Stefan
source to share
<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>
source to share
Try 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>
source to share
<LinearLayout>
<ScrollView>
<ListView ...>
</listView>
</ScrollView>
</LinearLayout>
You need to add LinearLayout
around the scroll, this way the scrollview knows where it should scroll. If that doesn't work, replace the ListView with a different LinearLayout and add your items to the LinearLayout. I'm not sure if I am View
capable of scrolling at all. Try the first option first, otherwise try the last one. I know the latter will work for sure, since I myself have used the same design in the application I am developing.
source to share