CardStackUI icon indicating copy to clipboard operation
CardStackUI copied to clipboard

Callback when card is clicked

Open MotassemJa opened this issue 8 years ago • 4 comments

Is there any callback to know when a card is clicked? Because you can't use the normal OnClickListener since it will override the behavior.

@tushar-acharya @mustafa01ali

MotassemJa avatar Jun 20 '17 12:06 MotassemJa

What exactly are you trying to do with an OnClickListener? One of the assumptions for this library is that you don't need to care about click events for individual cards, it just handles them for you and animates everything.

mustafa01ali avatar Jun 20 '17 14:06 mustafa01ali

@mustafa01ali I want to change the card content when it is selected. So I need to know which card is selected exactly to change the content based on the id of the selected card.

MotassemJa avatar Jun 21 '17 08:06 MotassemJa

You can try overloading CardStackAdapter#onClick() (https://github.com/mutualmobile/CardStackUI/blob/master/cardstack/src/main/java/com/mutualmobile/cardstack/CardStackAdapter.java#L227-L255).

mustafa01ali avatar Jun 21 '17 13:06 mustafa01ali

@MotassemJa Am solved by overriding onTouch() , onClick() Add below code to Your Adapter(Here MyCardStackAdapter.class)

add global boolean variable for adapter(HEre MyCardStackAdapter.class) : private boolean isReadyForHide = false;

@Override
public void onClick(View v) {
    super.onClick(v);
    isReadyForHide = true;
    v.findViewById(R.id.card_title).setVisibility(View.GONE);
    //Toast.makeText(mContext, "Clicked on my postion onClick : " + v.findViewById(R.id.edtAnswer).getTag(), Toast.LENGTH_SHORT).show();
}

@Override
public boolean onTouch(View v, MotionEvent event) {
    //  v.findViewById(R.id.edtAnswer).setVisibility(View.VISIBLE);
    if (isReadyForHide) {
        v.findViewById(R.id.card_title).setVisibility(View.VISIBLE);
        isReadyForHide = false;
    }
   // Toast.makeText(mContext, "Clicked on my postion onTouch : " + v.findViewById(R.id.edtAnswer).getTag(), Toast.LENGTH_SHORT).show();
    return super.onTouch(v, event);

}

sathishmscict avatar Mar 27 '18 12:03 sathishmscict