これは私のビューバインダーコードです。ここでは、受け入れボタンと拒否ボタンは機能しません。バターナイフのImageViewのonclicklistenerが機能しない
@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;
}
あなたは 'ButterKnife.bind(これ)を追加しました別の場所にコンテキストを使用する方法です;' onCreate' 'へ? –
自分のフラグメントクラスも追加しました。少し具体的にお願いしますか?この行はButterKnife.bind(this); 、私はフラグメントのonCreateメソッドでそれを追加することができません – Shan
こんにちは、あなたがそのフラグメントを使用する場合。 'inflater'ビューの後に' onCreateView'を実行すると 'ButterKnife.bind(this、view); 'を使うことができます[ここ](http://jakewharton.github.io/butterknife/)をチェックすることができます。 –