I am trying to make a glass breaking effect on a tinder like cardstack. The cards are working fine but I am having trouble getting the activity contextinto the adapter so I can use the brokenview plugin.
I have my mainactivity, on that activity I show a fragment and on that fragment I display the cardstack.
On that card stack I want to show a glass breaking animation when a user clicks a low rating button using this library:
https://github.com/zhanyongsheng/BrokenView
So in my adapter getview I set the context for the broken view with the context with this line:
mBrokenView = BrokenView.add2Window((MainActivity)this.getContext());
But when I run click on the button I am getting this error:
ClassCastException: com.mysampleapp.Application cannot be cast to com.mysampleapp.MainActivity
Thank you for your help.
Full code below:
public class SongPreviewCardsDataAdapter extends ArrayAdapter<SongDatabaseMappingAdapter> {
public SongPreviewCardsDataAdapter(Context context, int resource) {
super(context, resource);
}
ImageButton oneStarRating;
BrokenView mBrokenView;
private BrokenTouchListener listener;
@Override
public View getView(int position, final View contentView, ViewGroup parent) {
// Initialise Song Views
final SongDatabaseMappingAdapter item = getItem(position);
TextView songName = (TextView) (contentView.findViewById(R.id.songNameTextView));
songName.setText(item.getSongTitle());
// Initialise Rating Buttons
oneStarRating = (ImageButton) contentView.findViewById(R.id.ratingButton1);
if (item.getOneStarRating()) {
oneStarRating.setImageResource(R.drawable.starfull);
mBrokenView = BrokenView.add2Window((MainActivity)this.getContext());
listener = new BrokenTouchListener.Builder(mBrokenView).build();
songName.setOnTouchListener(listener);
}
try this instead:
mBrokenView = BrokenView.add2Window((MainActivity)(parent.getContext()));
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments