我有一个列表视图,我在其中创建了自定义适配器。当我向右滑动时,我正在显示一个按钮,所以我有 setOnTouchListener。我的问题是我想删除按钮并在开始滚动时显示另一个按钮。
以下是用于保持视图的适配器
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);
}
}
这是我显示 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();
}