1

This problem seem simple but I can not solve this problem now.

I have ListView in ScrollView (I know do not do this)

Now, with ListView in ScrollView I using custom view ExpandableHeightListView (how to make multiplelistview in Scrollview?) to show all item.

This is my scrollView

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp" android:orientation="vertical"
        android:id="@+id/layoutHero">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="ANTI-MAGE"
            android:id="@+id/txtName"
            android:gravity="center_horizontal"
            android:textSize="30sp"
            android:textStyle="bold"/>

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@mipmap/item_weapons"
            android:id="@+id/imageHero"
            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Carry - Nuker - Melee - Escape"
            android:gravity="center_horizontal"
            android:id="@+id/txtRoles"
            android:textSize="16sp"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_below="@id/layoutHero"
        android:id="@+id/layoutBio"
        android:layout_marginTop="5dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@color/material_blue_grey_800"></LinearLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="BIO"
            android:clickable="true"
            android:id="@+id/bioTextView"
            android:layout_marginTop="5dp"
            android:textSize="20dp"
            android:gravity="center_horizontal"
            android:textColor="#793838"
            android:textStyle="bold"/>

        <TextView
            android:layout_width="match_parent"
            android:paddingLeft="16dp"
            android:paddingRight="16dp"
            android:layout_height="wrap_content"
            android:id="@+id/txtBio"
            android:text="The monks of Turstarkuri watched kahfksajfhskald"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_below="@id/layoutBio"
        android:id="@+id/skillLayout"
        android:layout_marginTop="5dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@color/material_blue_grey_800"></LinearLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="OVERVIEW"
            android:layout_marginTop="5dp"
            android:id="@+id/overviewLayout"
            android:textSize="20dp"
            android:gravity="center_horizontal"
            android:textColor="#793838"
            android:textStyle="bold"/>

        <com.dotalibrary.ExpandableHeightListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/lstSkill"
            android:fadingEdge="none"
            android:focusable="false"
            android:scrollbars="none"
            android:nestedScrollingEnabled="true"
            >

        </com.dotalibrary.ExpandableHeightListView>
    </LinearLayout>
</RelativeLayout>

This is item of listView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/layoutLeft" android:orientation="horizontal">
    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:paddingTop="10dp"
        android:src="@mipmap/ic_launcher"
        android:id="@+id/imageAbility"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="5dp"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Mana Break"
            android:layout_toLeftOf="@id/imageAbility"
            android:id="@+id/txtAbility"
            android:textSize="18sp"
            />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="14sp"
            android:id="@+id/txtDetail"
            android:text="akjdfhakdfjhakdfjhadfkjhadkfjakdjfhadksjfhdakfjhadkfadfkjhadklfhafkldahfkasfh"/>


    </LinearLayout>
</LinearLayout>




<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingLeft="10dp"
    >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="NOTE: blah blahsalkfdjdlkj"
        android:id="@+id/txtAbilityNote"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/txtAffect"
        android:text="A modified technique of the Turstarkuri monks"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/txtAttribs"
        android:text="A modified technique of the Turstarkuri monks"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/txtDamage"
        android:text="A modified technique of the Turstarkuri monks"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/txtCmb"
        android:text="A modified technique of the Turstarkuri monks"/>

</LinearLayout>

This is custom class implement ListView

 public class ExpandableHeightListView extends ListView{

    boolean expanded = false;

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

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

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

    public boolean isExpanded()
    {
        return expanded;
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
        // HACK! TAKE THAT ANDROID!
        if (isExpanded())
        {
            // Calculate entire height by providing a very large height hint.
            // But do not use the highest 2 bits of this integer; those are
            // reserved for the MeasureSpec mode.
            int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
            super.onMeasure(widthMeasureSpec, expandSpec);

            ViewGroup.LayoutParams params = getLayoutParams();
            params.height = getMeasuredHeight();
        }
        else
        {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }

    public void setExpanded(boolean expanded)
    {
        this.expanded = expanded;
    }
}

Now, when I set data to ListView through Adapter. ListView do not show all item i had set. Example: I set 4 item, it only show 3 or 3.5 item

Who can give me advise about it ?

Thank you.

Community
  • 1
  • 1
Tran Vinh Quang
  • 585
  • 2
  • 9
  • 30
  • Do you ever change the `expanded` variable to `true` ? – Titus Nov 23 '15 at 09:43
  • the easiest way to handle this is to drop the lisview and replace it with linear layout, something like that http://stackoverflow.com/questions/28634232/set-adapter-to-linearlayout-instead-of-listview – AbuQauod Nov 23 '15 at 09:44
  • @Titus I already set lstSkill.setExpanded(true) in activity – Tran Vinh Quang Nov 23 '15 at 09:46
  • @MohammadAbuQauod Sorry but can you explain more ?. Because number of item in my listview usually change. How I can define LinearLayout ? – Tran Vinh Quang Nov 23 '15 at 09:48
  • my code was like this private void LoadList() { for (final MyClass _class : listOfMyClass) { LayoutInflater inflater = null; inflater = (LayoutInflater) a.getApplicationContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View mLinearView = inflater.inflate(R.layout.item_list_my_class, null); name1 = (TextViewCustom) mLinearView.findViewById(R.id.item_my_class_name); desc1 = (TextViewCustom) mLinearView.findViewById(R.id.item_my_class_desc); – AbuQauod Nov 23 '15 at 10:42
  • and the rest name1.setText(egas.getName()); desc1.setText(egas.getDescription()); mLinearListView.addView(mLinearView); mLinearView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {}});}} – AbuQauod Nov 23 '15 at 10:42

1 Answers1

0

You need to create a java custom ScrollView class and use it in your xml instead of original ScrollView. You can find the VerticalScrollview class code here: https://stackoverflow.com/a/13796159/3376613

Community
  • 1
  • 1
Hans Pour
  • 432
  • 6
  • 15