Help with Android Scroll

0

Well, I have a floating button in my view that prints out all the items that are in my listView. What happens is that when I click the floating button it takes a photo of the first 3 items and does not take away the rest, but in the end updates the listView to the next items. It looks like the code to get print is faster than updating the listView. When I click the floating button the screenShot function is called.

@Override

public void onScrollStateChanged(AbsListView view, int scrollState) {

    if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE){
        printScreen();
    }
}

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

public void screenShot (){
    if (list.getFirstVisiblePosition() == 0) {
        printScreen();
    } else {
        list.smoothScrollToPosition(0);
    }
}

public void printScreen(){
    int lastPosition = list.getLastVisiblePosition();
    int j = list.getFirstVisiblePosition();
    for (int i = j; i < lastPosition; i++){
        if (list.getChildAt(i) != null && list.getChildAt(i).isEnabled()) {
            JUtil.saveScreenShot(list.getChildAt(j), "operadora" + j + ".png");
        }
    }
    list.setSelection(lastPosition);
}
    
asked by anonymous 02.09.2015 / 15:51

1 answer

0

I changed the code and it was like this.

@Override

public void onScrollStateChanged(AbsListView view, int scrollState) {
    if (takingPictures && scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE){
        printScreen();
    }
}

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

public void screenShot (){
    takingPictures = true;
    nextPicture = 0;
    if (list.getFirstVisiblePosition() == 0) {
        printScreen();
    } else {
        list.smoothScrollToPosition(0);
    }
}

public void printScreen(){
    int lastPosition = list.getLastVisiblePosition();
    int firstPosition = list.getFirstVisiblePosition();
    for (int i = nextPicture; i <= lastPosition; i++){
        if (list.getChildAt(i - firstPosition) != null && list.getChildAt(i - firstPosition).isEnabled()) {
            JUtil.saveScreenShot(list.getChildAt(i - firstPosition), "NomeArquivo" + i + ".png");
        }
    }
    nextPicture = lastPosition + 1;
    if (nextPicture == list.getCount()){
        takingPictures = false;
        list.smoothScrollToPosition(0);
        Toast.makeText(rootView.getContext(), "Imagens salvas", Toast.LENGTH_SHORT).show();
    } else {
        int position = lastPosition + (lastPosition - firstPosition) + 1;
        if (position > list.getCount() - 1) {
            position = list.getCount() - 1;
        }
        list.smoothScrollToPosition(position);
    }
}
    
02.09.2015 / 18:04