我是初学Android开发者,我遇到了这个问题。对于使用Mindorks库的任何人,也许你可以就如何做到这一点提出建议。
下面使用的代码:
@Layout(R.layout.tinder_card_view)
public class TinderCard {
@View(R.id.profileImageView)
private ImageView profileImageView;
@View(R.id.nameAgeTxt)
private TextView nameAgeTxt;
@View(R.id.locationNameTxt)
private TextView locationNameTxt;
@View(R.id.profileInfo)
private ImageButton info;
@Click(R.id.profileInfo)
void openProfile()
{
//Call the fragment method
}
private Profile mProfile;
private Context mContext;
private SwipePlaceHolderView mSwipeView;
public TinderCard(Context context, Profile profile, SwipePlaceHolderView swipeView) {
mContext = context;
mProfile = profile;
mSwipeView = swipeView;
}
@Resolve
private void onResolved(){
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Bitmap bitmap = mProfile.getImage();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
Glide.with(mContext).load(byteArray).asBitmap().into(profileImageView);
//profileImageView.setImageBitmap(mProfile.getImage());
nameAgeTxt.setText(mProfile.getName() + ", " + mProfile.getAge());
locationNameTxt.setText(mProfile.getLocation());
}
我对Mindorks图书馆的了解有限。我的目标是让tinder_card_view布局有一个按钮,打开一个DialogFragment,显示用户的个人资料。
我怎么能这样做? TinderCard是一个简单的数据类,既不是Fragment也不是Activity,但它使用的布局不在ParentFragment的范围内,因此从这个类调用ParentFragment中的onClickListener看起来是不可能的。
我正在调用mSwipeView.addView(新的TinderCard(mContext,profile,mSwipeView));在我的父片段中创建一个TinderCard并将其放在我的SwipePlaceHolderView(Mindorks类)中,它将容纳Tinder卡。
源教程在这里: https://blog.mindorks.com/android-tinder-swipe-view-example-3eca9b0d4794
注意:@Click是一个注释,它将onClickListener设置为括号括起来的元素。 (我认为)