Reputation: 37
I am trying to make tinder swipe but keep getting an error: Cannot resolve symbol 'OnClickListener' I've already read some of the answers in similar questions but I couldn't fix it. Here is my code. Thnks in advance!
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.mindorks.placeholderview.SwipeDecor;
import com.mindorks.placeholderview.SwipePlaceHolderView;
import android.view.View.OnClickListener; /*Unused import statement*/
import com.mindorks.placeholderview.annotations.View;
public class MainActivity extends AppCompatActivity {
private SwipePlaceHolderView mSwipeView;
private Context mContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSwipeView = (SwipePlaceHolderView)findViewById(R.id.swipeView);
mContext = getApplicationContext();
mSwipeView.getBuilder()
.setDisplayViewCount(3)
.setSwipeDecor(new SwipeDecor()
.setPaddingTop(20)
.setRelativeScale(0.01f)
.setSwipeInMsgLayoutId(R.layout.tinder_swipe_in_msg_view)
.setSwipeOutMsgLayoutId(R.layout.tinder_swipe_out_msg_view));
for(Profile profile : Utils.loadProfiles(this.getApplicationContext())){
mSwipeView.addView(new TinderCard(mContext, profile, mSwipeView));
}
findViewById(R.id.rejectBtn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mSwipeView.doSwipe(false);
}
});
findViewById(R.id.acceptBtn).setOnClickListener(new View.OnClickListener/*Cannot resolve symbol 'OnClickListener'*/() {
@Override
public void onClick(View v) {
mSwipeView.doSwipe(true);
}
});
}
}
Upvotes: 0
Views: 310
Reputation: 164089
findViewById(R.id.rejectBtn)
returns a View
object, for which doesn't exist the method setOnClickListener()
, and not a Button
.
You need to cast this View
to a Button
and then set the listener:
((Button) findViewById(R.id.rejectBtn)).setOnClickListener(
....
)
Upvotes: 1