代码之家  ›  专栏  ›  技术社区  ›  Twing90

列表视图仅显示少数元素

  •  0
  • Twing90  · 技术社区  · 6 年前

    代码如下:

    @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);
                }
            });
    

    1 回复  |  直到 6 年前
        1
  •  0
  •   user8959091 user8959091    6 年前

    这是一种特殊的行为,但由于筛选器解决了它,请尝试:

    adapter.getFilter().filter("");
    

    lV_titoli.setAdapter(adapter);