[英]Can't fix an Error: Cannot resolve symbol 'OnClickListener'
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. 我正在尝试轻扫火种,但仍然出现错误:无法解析符号“ OnClickListener”我已经阅读了类似问题中的一些答案,但无法解决。 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);
}
});
}
}
findViewById(R.id.rejectBtn)
returns a View
object, for which doesn't exist the method setOnClickListener()
, and not a Button
. findViewById(R.id.rejectBtn)
返回一个View
对象,该对象不存在setOnClickListener()
方法,而不是Button
。
You need to cast this View
to a Button
and then set the listener: 您需要将此
View
转换为Button
,然后设置侦听器:
((Button) findViewById(R.id.rejectBtn)).setOnClickListener(
....
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.