-1

这是我的视图活页夹代码。此处的接受按钮和拒绝按钮不起作用。

@Layout(R.layout.item)
public class TinderCard implements AsyncTaskCompleteListener {

SessionManager msession;
private static final String LIKE = "1";
private static final String DISLIKE = "2";
private int size,match;
String suggestionid;
private FindMatchesExecute execute;
@View(R.id.profileImageView)
private ImageView profileImageView;

@View(R.id.nameAgeTxt)
private TextView nameAgeTxt;

@View(R.id.acceptBtn)
private ImageView acceptbutton;


@View(R.id.rejectBtn)
private ImageView dislike_button;

private Data mProfile;
private Context mContext;
public int count=0;



@View(R.id.swipeView)
private SwipePlaceHolderView mSwipeView;
Activity activity;
public TinderCard(Context context, Data profile, SwipePlaceHolderView swipeView,FindMatchesExecute execu) {
    mContext = context;
    mProfile = profile;
    mSwipeView = swipeView;
    this.execute=execu;
    msession=new SessionManager(mContext);


}

@Resolve
private void onResolved(){
    Glide.with(mContext).load(mProfile.getPicture()).into(profileImageView);
    nameAgeTxt.setText(mProfile.getName() + ", " + mProfile.getAge());

    suggestionid=mProfile.getUserid();
    profileImageView.setOnClickListener(new android.view.View.OnClickListener() {
        @Override
        public void onClick(android.view.View v) {
            Intent i=new Intent(mContext,UserProfile.class);
            i.putExtra("suggestion_id",mProfile.getUserid());
            mContext.startActivity(i);
        }
    });

接受和拒绝按钮的侦听器部分不起作用。我的代码中缺少什么。

    acceptbutton.setOnClickListener(new android.view.View.OnClickListener() {
        @Override
        public void onClick(android.view.View v) {
            mSwipeView.doSwipe(true);
        }
    });
    dislike_button.setOnClickListener(new android.view.View.OnClickListener() {
        @Override
        public void onClick(android.view.View v) {
            mSwipeView.doSwipe(false);

        }
    });
}


@SwipeOut
private void onSwipedOut(){

    Log.d("shan", "onSwipedOut");
    HashMap<String, String> map = new HashMap<>();
    map.put(Const.URL, Constant.like_dislike);
    map.put(Const.Params.TOKEN, msession.getToken());
    map.put(Const.Params.ID, msession.getID());

    map.put(Const.Params.LIKE_DISLIKE_STATUS, DISLIKE);


    map.put(Const.Params.SUGGESTION_ID, suggestionid);

    Log.d("shanUpdatePref", "login map" + map);

    // new MultiPartRequester(this, map, Const.ServiceCode.UPDATE_DOB, this);
    new HttpRequester(mContext, Const.POST, map, Const.ServiceCode.LIKE_DISLIKE, this);
    execute.onExecute();
}

@SwipeCancelState
protected void onSwipeCancelState(){
    Log.d("EVENT", "onSwipeCancelState");
}

@SwipeIn
private void onSwipeIn()
{
    //FindMatchesFragment.size--;
    HashMap<String, String> map = new HashMap<>();
    map.put(Const.URL, Constant.like_dislike);
    map.put(Const.Params.TOKEN, msession.getToken());
    map.put(Const.Params.ID, msession.getID());

        map.put(Const.Params.LIKE_DISLIKE_STATUS, LIKE);


    map.put(Const.Params.SUGGESTION_ID, suggestionid);

    Log.d("shanUpdatePref", "login map" + map);


    new HttpRequester(mContext, Const.POST, map, Const.ServiceCode.LIKE_DISLIKE, this);
    execute.onExecute();
}

@SwipeInState
private void onSwipeInState(){
    Log.d("EVENT", "onSwipeInState");
}

@SwipeOutState
private void onSwipeOutState(){
    Log.d("EVENT", "onSwipeOutState");
}

@Override
public void onTaskCompleted(String response, int serviceCode) {
    JSONObject jsonObject;
    switch (serviceCode) {
        case Const.ServiceCode.LIKE_DISLIKE:
            Log.d("shan", "task1");
            Log.d("shanResponse",response);
            try {
                jsonObject = new JSONObject(response);


                if (jsonObject.getString("success").equals("true")) {

                    JSONObject like= jsonObject.getJSONObject("like");
                    Log.d("shanStatus",like.optString("status"));

                    match=like.optInt("match");
                    if(match==1)
                    {
                        String picture=like.optString("picture");
                        String user_pictre=like.optString("user_image");
                        String name=like.optString("name");
                        String userid=like.optString("suggestion_id");
                        Fragment MatchFoundScreen = new MatchFoundScreen();
                        Bundle args = new Bundle();
                        args.putString("name", name);
                        args.putString("picture",picture);
                        args.putString("user_image", user_pictre);
                        args.putString("suggestion_id", userid);
                        args.putInt("match",match);
                        MatchFoundScreen.setArguments(args);
                        FragmentManager fragmentManager =((FragmentActivity) mContext).getSupportFragmentManager();

                        fragmentManager.beginTransaction().replace(R.id.frame, MatchFoundScreen).commit();

                    }



                } else {
                    Utility.showShortToast(mContext, jsonObject.getString("error_message"));
                }
            }  catch (JSONException e) {
                e.printStackTrace();
            }

            break;
    }
}

}

有人请指导我解决这个问题。提前致谢。

这是我的片段类。

 @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    msession = new SessionManager(getActivity());

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {


    Log.i("Find Match", "oncreateview called");
    view = inflater.inflate(R.layout.find_matches, null);
    rlayout=(LinearLayout) view.findViewById(R.id.likedislikebuttonlayout);
    frame=(FrameLayout)view.findViewById(R.id.frame2);
    LocationManager locationManagerresume = (LocationManager) getActivity().getSystemService(LOCATION_SERVICE);
    if (!locationManagerresume
            .isProviderEnabled(LocationManager.GPS_PROVIDER)) {

        showGPSDisabledAlertToUser();
    }

    cd = new ConnectionDetector(getActivity());
    if (!cd.isConnectingToInternet()) {

        Toast.makeText(getActivity(), "No Internet", Toast.LENGTH_SHORT)
                .show();

    }

    mSwipeView = (SwipePlaceHolderView)view.findViewById(R.id.swipeView);
    rippleBackground = (RippleBackground) view.findViewById(R.id.content);
    rippleBackground.startRippleAnimation();

    noUsers=(TextView)view.findViewById(R.id.noUsers);
    profileimage = (CircleImageView) view.findViewById(R.id.profileimage);
   Glide.with(getActivity()).load(msession.getProfileImage())
   .into(profileimage);
    mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
              .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();


    mLocationRequest = LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(10 * 1000)
            .setFastestInterval(1 * 1000);
    al = new ArrayList<>();
    mContext = getActivity();


    mSwipeView.getBuilder()
            .setDisplayViewCount(1)
            .setSwipeDecor(new SwipeDecor()
                    .setPaddingTop(20)
                    .setRelativeScale(0.01f)
                    .setSwipeInMsgLayoutId(R.layout.tinder_swipe_in_msg_view)
                    .setSwipeOutMsgLayoutId(R.layout.tinder_swipe_out_msg_view));




    return view;
}
4

2 回答 2

0

ButterKnife.bind(getActivity())在活动使用this和片段使用时使用getActivity()

这是一种在不同地方使用上下文以获取更多详细信息的方式

于 2016-10-22T06:35:18.340 回答
0
 @OnClick(R.id.iv_image)
void ivBack() {
    //TODO For Back Action
    finish();
}

使用最新的

compile 'com.jakewharton:butterknife:8.1.0'
apt 'com.jakewharton:butterknife-compiler:8.1.0'

有关 lib 的更多详细信息

于 2016-10-22T06:39:42.350 回答