我想知道如何使用这种方法:
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.setEventNameName(i + "");
holder.settheColor(Color.parseColor("#000000"));
}
static int i;
class ViewHolder extends RecyclerView.ViewHolder{
public TextView eventName;
public RelativeLayout theLayout;
public ViewHolder(final View itemView) {
super(itemView);
eventName = (TextView)itemView.findViewById(R.id.eventName);
theLayout = (RelativeLayout)itemView.findViewById(R.id.backgroundevent);
theLayout.setId(++i);
theLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getAdapterPosition()>0){
removeItem(getAdapterPosition());
}else {
addItem("");
}
}
});
}
public void settheColor(int theColor){
theLayout.setBackgroundColor(Color.parseColor(String.valueOf(theColor)));
}
public void setEventNameName(String TheEventName){
eventName.setText(TheEventName);
}
}
将其附加到类似的链接:
$('[data-jump-spy]').each(function(){
var dataObj = .data('jump-spy');
$(this).onclick ({
scrollTop: $("#" + dataObj ).offset().top();
});
});
最终解决方案可以在下面找到
此功能可让您更轻松地对网站进行编码。只需输入<a href="javascript:void(0);" data-jump-spy="divContentThatsFarDownPage">Who we are</a>
....
....
....
....
<div class="box radius box-grey --animate" id="divContentThatsFarDownPage">
....
</div>
<div class="whatever iconArrow-to-Content LinkText-to-Content Img-to-Content" data-jump-spy="page-content"
答案 0 :(得分:2)
一些改变
$('[data-jump-spy]').each(function(){
var dataObj = $(this).data('jump-spy'); // needs $(this) at beginning since .data needs to run on some object
$(this).click(function(){ // used click instead of onclick and you need to pass a function as an argument
$('html,body').animate({scrollTop: $("#" + dataObj ).offset().top}); // use .top instead of .top() as it is a property and not a method
});
});