我在每个项目上都有一个TextView,并在var eventPage = 2;
var blank = false; // Flag for empty Ajax response
$(window).scroll(function() {
if ( ($(window).scrollTop() == $(document).height() - $(window).height()) && !blank ) { // Add !blank to the condition
$.ajax({
url: ajaxUrl,
type: 'post',
data: {
action: 'load_events_by_ajax',
page: eventPage,
security: '<?php echo wp_create_nonce("load_more_events"); ?>'
},
beforeSend: function() {
$('body').loading({
stoppable: true,
theme: 'dark'
});
},
success: function(response) {
$('body').loading('stop');
$('.EventThumbRow').append(response);
eventPage++;
if (response == ""){
blank = true; // Turn the flag to true to skip subsequent Ajax requests.
}
},
error: function(xhr) {
$('body').loading('stop');
}
});
}
});
上添加了holder.item_edit_text.addTextChangedListener
以获得很长的列表,还提供了一个在片段级别上计算总数的界面,但是当用户在一个视图上键入{{ 1}}在多个项目上被调用。
例如,如果用户输入5,则根据回收率(列表中的项目数),我会得到5的倍数,例如15或25
RECYCLERVIEW onBindViewHolder
onBindViewHolder
问题是我如何确保每次在recyclerview中为一项调用onBindViewHolder
片段
holder.item_edit_text.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence amount, int start, int before, int count) {
calculateTotal.onAmountAdded(current, amount.toString());
}
@Override
public void afterTextChanged(Editable s) {
}
});
@Override
public int getItemCount() {
if (Accounts != null) {
return Accounts.size();
}
return 0;
}
答案 0 :(得分:0)
我想没有足够的信息。
不是在viewBinder上添加TextWatcher
将其添加到您的ViewHolder类中
class ViewHolder extends RecyclerView.ViewHolder {
private TextView item_edit_text;
ViewHolder(View itemView) {
super(itemView);
item_edit_text = itemView.findViewById(R.id.item_edit_text);
item_edit_text.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence amount, int start, int before, int count) {
//not sure why this current variable is for
//if its current Account
Accounts current = Accounts.get(getLayoutPosition());
calculateTotal.onAmountAdded(current, amount.toString());
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
}