我正在尝试轻扫火种,但始终收到错误消息:无法解析符号“ OnClickListener” 我已经阅读过类似问题中的一些答案,但无法解决。这是我的代码。提前谢谢!
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);
}
});
}
}
答案 0 :(得分:1)
Required ArgumentMatcher<List<Person>>
found: (???) -> Boolean
返回一个findViewById(R.id.rejectBtn)
对象,该对象不存在方法View
,而不是setOnClickListener()
。
您需要将此Button
强制转换为View
,然后设置侦听器:
Button