1

I need something like a table with two columns and dynamic no. of rows (which increases and decreases according to the length of data i receive ). Currently what I have done is, I added to listviews in a horizontal linear layout so it looks like a table. But the issue is both the listview's scrolling is independent of other. I need to lock the scrolling so if i scroll both will not move independently.

All the data in the listview are readonly (just for display purpose).

is it possible to sync the scroll or is there any better way by which my requirements can be met?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

1

If you you want to stop the first list view scroll while scrolling the 2nd list and vice versaa other.Then put the Scroll listner for the lsitviews and block the other listview scrolling. here is example

  listview1.setOnScrollListener(new OnScrollListener() {
            private int mLastFirstVisibleItem;

            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {

           if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {
                listview1.setEnabled(true);
                listview2.setEnabled(true);
                Log.i("a", "scrolling stopped...");
            }

            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem,
                    int visibleItemCount, int totalItemCount) {

                  listview2.setEnabled(false);

            }
        });

Same way for the second list view

listview2.setOnScrollListener(new OnScrollListener() {
        private int mLastFirstVisibleItem;

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {

       if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {

            listview1.setEnabled(true);
            listview2.setEnabled(true);
            Log.i("a", "scrolling stopped...");
        }

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem,
                int visibleItemCount, int totalItemCount) {

            listview1.setEnabled(false);


        }
    });
King of Masses
  • 18,405
  • 4
  • 60
  • 77
  • 1
    I don't want to stop scrolling of either one view. What i need is to scroll both the listviews simultaneously without using multitouch. So it will look like a table when i scroll. – Paul_Varghese Jul 25 '17 at 08:00
  • Ok then you can look into this https://stackoverflow.com/questions/12342419/android-scrolling-2-listviews-together or https://stackoverflow.com/questions/8371743/scrolling-listviews-together?lq=1 – King of Masses Jul 25 '17 at 08:29