这是我的查看活页夹代码。这里的acceptbutton和reject按钮不起作用。
@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;
}
答案 0 :(得分:0)
当您使用活动ButterKnife.bind(getActivity())
时使用this
,使用getActivity()
使用片段。
这是在不同地方for more details
使用上下文的一种方式答案 1 :(得分: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'