我有800个标题用于实现列表视图。我将这800个标题放在一个字符串数组中,然后尝试填充列表视图,但是当我尝试运行时,我只能显示至少10个元素。当我尝试使用搜索栏搜索标题时,可以找到它,然后在删除过滤器搜索时可以看到标题的总数组。我错了吗? 这是代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_titoli);
btt_backHome = (Button) findViewById(R.id.btt_backHome);
lV_titoli = (ListView) findViewById(R.id.lV_titoli);
eT_search = (EditText) findViewById(R.id.eT_search);
adapter = ArrayAdapter.createFromResource(this, R.array.titoli, android.R.layout.simple_list_item_1);
adapter_testi = ArrayAdapter.createFromResource(this, R.array.testi, android.R.layout.simple_list_item_1);
lV_titoli.setAdapter(adapter);
final Intent refresh = new Intent(this, activity_titoli.class);
final Intent to_Home = new Intent (this , Activity_Main.class);
final Intent to_Canzone_from_titoli = new Intent (this , activity_canzone.class);
eT_search.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
(activity_titoli.this).adapter.getFilter().filter(arg0);
}
});
我已经验证了名为“ titoli”的字符串数组是正确的。
答案 0 :(得分:0)
这是一种特殊的行为,但由于过滤器可以解决,请尝试:
class Registration < ApplicationRecord
belongs_to :student
belongs_to :course
validates_uniqueness_of :student_id, :scope => :course_id
validate :period_is_free
private
def period_is_free
if student.courses.where(period: course.period)
errors.add(:courses, "Student is already registered for a class at this period")
end
end
end
紧接着
adapter.getFilter().filter("");