daimajia / AndroidSwipeLayout

The Most Powerful Swipe Layout!
MIT License
12.38k stars 2.67k forks source link

Close the SurfaceView by Clicking BottomView in a ListView for #241

Closed noxevolution closed 8 years ago

noxevolution commented 8 years ago

Hi, I am sort of new to android development, I am working on my small app and I need a swipe feature for this. So I did a little bit searching and I found this amazing library. Now What I want to do is the frontview or SurfaceView will be closed when I clicked on the hiddenview or BottomView .. How can I accomplish this?? Please any help would be appreciated!!!!

this is my adapter code,

public class ListViewAdapter extends BaseSwipeAdapter { SwipeLayout swipeLayout; private Context mContext; private int position; private String[] arr; TextView textView; LinearLayout linearLayout;

public ListViewAdapter(Context mContext, int position, String[] arr) {
    this.mContext = mContext;
    this.position = position;
    this.arr = arr;
}

@Override
public int getSwipeLayoutResourceId(int position) {
    return R.id.swipe;
}

@Override
public View generateView(int position, ViewGroup parent) {

    View v = LayoutInflater.from(mContext).inflate(R.layout.listview_item, null);
    swipeLayout = (SwipeLayout)v.findViewById(getSwipeLayoutResourceId(position));
    linearLayout = (LinearLayout)v.findViewById(R.id.HideLayout);
    textView = (TextView)v.findViewById(R.id.delete);

    swipeLayout.addSwipeListener(new SimpleSwipeListener() {
        @Override
        public void onOpen(SwipeLayout layout) {

            //YoYo.with(Techniques.Tada).duration(500).delay(100).playOn(layout.findViewById(R.id.trash));
        }
    });
    swipeLayout.setOnDoubleClickListener(new SwipeLayout.DoubleClickListener() {
        @Override
        public void onDoubleClick(SwipeLayout layout, boolean surface) {
            Toast.makeText(mContext, "DoubleClick", Toast.LENGTH_SHORT).show();

        }
    });

    swipeLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(swipeLayout.getOpenStatus() == SwipeLayout.Status.Open){
                swipeLayout.close();
            }
        }
    });

    return v;
}

@Override
public void fillValues(int position, View convertView) {
    TextView t = (TextView)convertView.findViewById(R.id.position);
    t.setText(arr[position]);
}

@Override
public int getCount() {
    return 20;
}

@Override
public Object getItem(int position) {
    return null;
}

@Override
public long getItemId(int position) {
    return position;
}

}

ding102992 commented 8 years ago

That's simple.You can set a id for the bottomView,and find it in adapter,then set OnclickListener for this view.In this listener,you could set a callback and register in the activity where adapter is.In the method of callback,call swipeLayout.close().That's all.Maybe my description will confuse you.I'll give you a full answer tomorrow,It's too late in China now.