1

I'm working on a program that shows the image. enter image description here

This is a ListView and GridView wrapped in ScrollView. The program works as follows: when you click on GridView item, selected item is added to the ListView, thus it is possible to add several items into the ListView. Consequently, it is possible to scroll through the entire contents of ScrollView. Everything works fine until ListView contains a large amount of data, in this case adding and rendering of the new ListView will slow down significantly. Therefore, I would like to ask if anyone dealt with similar problem and knows better way to resize and redraw the entire ListView.

Currently I perform the calculation and adjust the size of ListView as follows:

public ListUtils(ListView listView){
    ListAdapter adapter = listView.getAdapter();

    int count = adapter.getCount();
    int itemsHeight;    

    View oneChild = listView.getChildAt(0);
    if( oneChild == null){
        return;
    }

    itemsHeight = oneChild.getHeight();

    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)listView.getLayoutParams();
    params.height = (itemsHeight * count);
    listView.setLayoutParams(params);
}
elementstyle
  • 1,021
  • 1
  • 10
  • 17
  • Take a look at this question: http://stackoverflow.com/a/11406856/1919749 – ismaestro Mar 27 '15 at 21:13
  • I think a listview itself is scrollable by default. Not sure if the scrollview is necessary, actually... http://stackoverflow.com/questions/13679633/how-to-make-android-listview-scrollable – Benjamin S Mar 27 '15 at 21:17
  • It is clear to me that the ListView is scrollable but I want to scroll through the ListView and GridView at the same time – elementstyle Mar 28 '15 at 08:34

1 Answers1

1

If you're having performance issues with the ListView you're using I'd recommend switching to a RecyclerView and use a custom RecyclerView.Adapter. Take a look here and here.

Filipe Silva
  • 220
  • 4
  • 10