我在我的应用程序中使用这个库:卡片库:指南并创建了一张卡片,如示例所示。现在我需要处理一个单击事件,但是在实例化以下内容时收到错误:new Card.OnCardClickListener
,其中说OnCardClickListener is abstract: cannot be instantiated
. 在我的活动中,我有以下代码:
Card card = new Card(getBaseContext());//getContext()
CardHeader header = new CardHeader(getBaseContext());
card.addCardHeader(header);
final CardViewNative cardView = (CardViewNative) findViewById(R.id.carddemo);
cardView.setCard(card);
cardView.setClickable(true);
cardView.setOnClickListener(new Card.OnCardClickListener()); //error here
怎么了?如何将我的卡片设置为可点击,然后处理点击/触摸事件?
编辑
如果我这样使用它:
cardView.setOnClickListener(new Card.OnCardClickListener(){//error here
@Override
public void onClick(Card card, View view) {
// This will execute when the the card is clicked
}
});
它说cannot resolve method setOnClickListener(it.gmariotti.cardslib.library.internal.Card.OnCardClickListener)
编辑1
各位是对的,我setOnClickListener
在卡片上自己设置了,现在没有错误了,
但是点击卡片时它仍然没有执行任何操作。这是新代码:
//Create a Card
Card card = new Card(this);//getContext()
//Create a CardHeader
CardHeader header = new CardHeader(this);
//....
//Add Header to card
card.addCardHeader(header);
//Set card in the cardView
CardViewNative cardView = (CardViewNative) this.findViewById(R.id.carddemo);
cardView.setCard(card);
card.setClickable(true);
card.setOnClickListener(new Card.OnCardClickListener(){
@Override
public void onClick(Card card, View view) {
// This will execute when the the card is clicked
Toast.makeText(CardMariotti.this,"Clickable card", Toast.LENGTH_LONG).show();
}
});
我进行了调试,但onClick
从未调用过该方法。怎么来的?