How can i handle setOnScrollListener for Custom View android

左心房为你撑大大i 提交于 2019-12-13 19:17:18

问题


I have a list view where i created custom adapter. I am displaying a button when i swipe right, so i have setOnTouchListener. My problem is i want to remove the button and display another button when i start scrolling.

Following is the adapter for holding the view

public static final class TransactionAddDropViewHolder {

public View moveUpButton = null;
public View moveDownButton = null;
public View withdrawButton = null;
public View reviewButton = null;

public View approveButton = null;
public View rejectButton = null;

public LinearLayout addContainer = null;
public LinearLayout dropContainer = null;



public void swipeButtons() {
    addDropListView.setOnTouchListener(new OnSwipeTouchListener() {
    boolean isDeleteShowing = false;
        public void onSwipeRight() {
            if(!isDeleteShowing){
               withdrawButton.setVisibility(View.VISIBLE);
               isDeleteShowing = true;
             } else {
                 onScrollChanged();
                 isDeleteShowing = false;
             }
        }

        public void onSwipeLeft() {
            withdrawButton.setVisibility(View.INVISIBLE);
        }
    });
}

public void onScrollChanged(){

addDropListView.setOnScrollListener(new OnScrollListener() {

@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
    Log.i("scrollStateChanged", "Changed");
}    
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
    if(scrollState==SCROLL_STATE_IDLE){

         }
    }
  });
}

public void showUserButtons() {
    this.moveUpButton.setVisibility(View.VISIBLE);
    this.moveDownButton.setVisibility(View.VISIBLE);
    // this.withdrawButton.setVisibility(View.VISIBLE);
}

public void hideUserButtons() {
    this.moveUpButton.setVisibility(View.GONE);
    this.moveDownButton.setVisibility(View.GONE);
    // this.withdrawButton.setVisibility(View.GONE);
} 

}

And this is my Custom View where i am displaying the onSwipeButton getView.

@Override
public View getView(final int position, View convertView,
        ViewGroup parent) {

    final TransactionAddDrop addDropData = this.addDropList.get(position);

    TransactionAddDropViewHolder holder = null;

    if (convertView == null) {
        convertView = inflater.inflate(R.layout.fragment_pending_transaction_list_item, null);
        holder = new TransactionAddDropViewHolder();

        holder.withdrawButton = convertView.findViewById(R.id.pendingTransactionItem_withdrawButton);
        holder.addContainer = (LinearLayout) convertView.findViewById(R.id.pendingTransactionItem_addContainer);
        **holder.swipeButtons();** 
        convertView.setTag(holder);
    } else {
        holder = (TransactionAddDropViewHolder) convertView.getTag();
        holder.swipeButtons(); 
    }

来源:https://stackoverflow.com/questions/16268200/how-can-i-handle-setonscrolllistener-for-custom-view-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!