Reputation: 608
Goal
I want to have a list (not a ListView) in a scrollView
Problem
ListView in ScrollView does not work
Possible solution
I think the solution is todo the following:
problems with the solution
If i place the extended AdapterView in my xml layout the app crashes.
Error: 10-04 16:02:14.396: W/ActivityManager(2119): Activity pause timeout for ActivityRecord{422c1838 package/.activities.SelectWorkplaceActivity}
Questions
What is going wrong here?
Are there better ways to create a non-scrollable list with a adapter?
Code
The View:
public class BasicListView extends AdapterView<ListAdapter> {
private String tag = "BasicListView";
private ListAdapter mAdapter;
private DataSetObserver mDataSetObserver;
private Context mContext;
public BasicListView(Context context) {
super(context);
mContext = context;
}
public BasicListView(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
}
public BasicListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mContext = context;
}
@Override
public ListAdapter getAdapter() {
return mAdapter;
}
@Override
public View getSelectedView() {
Log.i(tag, "getSelectedView not available");
return null;
}
@Override
public void setAdapter(ListAdapter adapter) {
if(mAdapter != null)
{
mAdapter.unregisterDataSetObserver(mDataSetObserver);
}
mAdapter = adapter;
requestLayout();
}
@Override
public void setSelection(int position) {
Log.i(tag, "setSelection not available");
}
}
And the XML Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Code scannen" />
<Button
android:id="@+id/btn_scan_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Scan werkplek" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Code handmatig invoeren" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/et_type_code"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" >
</EditText>
<Button
android:id="@+id/btn_send_code"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Verzenden" />
</LinearLayout>
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_current_sessions"
/>
<package.views.BasicListView
android:id="@+id/current_sessions"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</package.views.BasicListView>
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="@string/label_favorite_workplaces"
/>
<ListView
android:id="@+id/favorite_workplaces"
android:layout_width="match_parent"
android:layout_height="193dp"
/>
</LinearLayout>
</ScrollView>
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/actionbar" />
if you want more info please just ask :)
Upvotes: 2
Views: 5700
Reputation: 1020
This answer from Romain Guy explains why you should use a LinearLayout rather than a ListView for this purpose: https://stackoverflow.com/a/3496042/1717225
Upvotes: 3