-1

Please help me to scroll the database list. Its displaying only 3 database files and I am not able scroll that database list. Please help me to fix this issue. I am beginner for android.

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/White"
    android:gravity="center|top"
    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:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="information"
        android:textSize="22dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:background="@color/DarkGray"
        android:gravity="center|top"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="information"
            android:textColor="@color/DarkMagenta"
            android:textSize="20dp" />

        <View
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:layout_marginTop="10dp"
            android:background="@color/Black" />

        <TextView
            android:id="@+id/backupView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Select storage location"
            android:textSize="18dp" />

        <RadioGroup
            android:id="@+id/radioGroupBackup"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal" >

            <RadioButton
                android:id="@+id/phoneBackupRb"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Phone Memory" />

            <RadioButton
                android:id="@+id/externalBackupRb"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="External Memory" />
        </RadioGroup>

        <Button
            android:id="@+id/backupBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:onClick="onClickBackup"
            android:text="Back Up" />

        <TextView
            android:id="@+id/backupSuccessView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            android:layout_marginTop="15dp"
            android:text=""
            android:textSize="15dp" />

        <Button
            android:id="@+id/AutobackupBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:onClick="onClickAutoBackup"
            android:text="Auto BackUp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:layout_marginBottom="30dp"
        android:background="@color/DarkGray"
        android:gravity="center|top"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="information"
            android:textColor="@color/DarkMagenta"
            android:textSize="20dp" />

        <View
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:layout_marginTop="10dp"
            android:background="@color/Black" />

        <TextView
            android:id="@+id/restoreView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Select storage location"
            android:textSize="18dp" />

        <RadioGroup
            android:id="@+id/radioGroupRestore"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal" >

            <RadioButton
                android:id="@+id/phoneRestoreRb"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Phone Memory" />

            <RadioButton
                android:id="@+id/externalRestoreRb"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="External Memory" />
        </RadioGroup>

        <View
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:layout_marginTop="10dp"
            android:background="@color/Black" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="20dp"
            android:text="Select database file to restore"
            android:textSize="20dp" />

        <TextView
            android:id="@+id/restoreResult"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp"
            android:text=""
            android:textSize="15dp" />
    </LinearLayout>

    <ListView
            android:id="@+id/listDatabase"
            android:layout_width="fill_parent"
            android:layout_height="150dp" />
</LinearLayout>

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
  • where is the scrollview in this layout? and you cannot use list view inside scroll view in android. – Remees M Syde Dec 14 '15 at 13:28
  • Its there. Since there is no space to insert, I didn't inserted. – Huccha Venkat Dec 14 '15 at 13:32
  • So it gets show but you can't scroll it? You should show the part where scrollview is being used. – danizmax Dec 14 '15 at 13:43
  • I can scroll the main layout but i can't scroll database list (ListView). Here, only 3 database files displayed which has more database files. – Huccha Venkat Dec 14 '15 at 13:47
  • @HucchaVenkat Shouldnt do that, post your question with what is in your current code. And its not possible to do your requirement with a simple list inside scrollview. You need some customization. here you can find some ways to do that. http://stackoverflow.com/questions/6210895/listview-inside-scrollview-is-not-scrolling-on-android – Remees M Syde Dec 14 '15 at 14:17
  • @Remees M Syde "" Which one I missed in my current code which is posted above. – Huccha Venkat Dec 14 '15 at 14:20
  • OK, have you tried the link provided? it has some options to do your requirement. – Remees M Syde Dec 14 '15 at 15:40
  • Ya tried but no use, still same issue occurs. – Huccha Venkat Dec 14 '15 at 16:23

3 Answers3

0

Maybe it's better to move your ListView in other Activity, which will extend ListActivity. Then it will definitely be scrollable.

Ksenia
  • 3,453
  • 7
  • 31
  • 63
0

Hi By default listview can't add inside a scrollview.For doing this you need to either calculate the size of list view based on item or you need to override the onMeasure of listview.

Added below a custom Listview with overrid onMeasure method use this listview instead of the default one.Also make sure in xml file the heigh should be wrap_content.

Also make scrollview's fillviewport property to true inorder to use full height.

 public class MyListView extends ListView {

public MyListView(Context context) {
    super(context);
}

public MyListView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public MyListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int heightSpec;

    if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) {

        // The two leftmost bits in the height measure spec have
        // a special meaning, hence we can't use them to describe height.
        heightSpec = MeasureSpec.makeMeasureSpec(
                Integer.MAX_VALUE >>2, MeasureSpec.AT_MOST);
    }
    else {
        // Any other height should be respected as is.
        heightSpec = heightMeasureSpec;
    }

    super.onMeasure(widthMeasureSpec, heightSpec);
}  
} 
Arun Antoney
  • 4,292
  • 2
  • 20
  • 26
  • Should I create new activity for this or use old activity "public class BackupActivity extends Activity implements OnItemClickListener {". – Huccha Venkat Dec 14 '15 at 14:17
  • there is nothing you need to change use this new listview in your xml file .Once you created above class you can access it in your xml file – Arun Antoney Dec 14 '15 at 14:31
0

public void showListView() {

dbList = (ListView) findViewById(R.id.listDatabase);
ListAdapter listAdapter = dbList.getAdapter();
    if (listAdapter == null) {
        // pre-condition
        return;
    }
    int totalHeight = 0;
    int desiredWidth = MeasureSpec.makeMeasureSpec(
            dbList.getWidth(), MeasureSpec.AT_MOST);
    for (int i = 0; i < listAdapter.getCount(); i++) {
        View listItem = listAdapter.getView(i, null, dbList);
        listItem.measure(desiredWidth,
                MeasureSpec.UNSPECIFIED);
        totalHeight += listItem.getMeasuredHeight();
    }

    ViewGroup.LayoutParams params = dbList.getLayoutParams();
    params.height = totalHeight
            + (dbList.getDividerHeight() * (listAdapter
                    .getCount() - 1)) + 30;
    dbList.setLayoutParams(params);
    dbList.requestLayout();

}