如何优化Android ListView?

fra*_*ish 2 android listview

我已经定制了我的ListAdapter,我在一行中显示了3个不同的图像(项目).它完美地工作(根据它的功能).但是,无法顺利滚动ListView.

我在ImageViews上使用setBackgroundImage,我使用HashMap来缓存resourceId; 所以我不必使用

resId=getContext().getResources().getIdentifier(resName, "drawable",appContext.getPackageName());

一次又一次.

我想我错过了一些东西,因为ListView不能很好地滚动.此外,如果我在平板电脑上尝试它,我的代码会连续自动填充超过3个项目,平板电脑的列表视图几乎不可滚动.

我在这做错了什么?

更新:

我在我的Flags(国家标志)中以编程方式创建ListView的Activity的onCreate方法:

root=(ViewGroup)this.findViewById(R.id.root);

    listView=new ListView(this);
    listView.setLayoutParams(new LayoutParams(
        LayoutParams.MATCH_PARENT,
        LayoutParams.MATCH_PARENT));

    /*
    ArrayList<Country> dataList=new ArrayList<Country>(){{
        add(new Country("jp"));
        add(new Country("de"));
        add(new Country("it"));
    }};*/

    CountryListAdapter countryListAdapter=new CountryListAdapter(this);


    countryListAdapter.setDataSource(allCountries);


    listView.setAdapter(regionListAdapter);
    listView.setBackgroundColor(0xFF000000);
    listView.setDividerHeight(0);

    root.addView(listView);
Run Code Online (Sandbox Code Playgroud)

resId=getContext().getResources().getIdentifier(resName, "drawable",appContext.getPackageName());

Mar*_*era 9

学习,研究和学习;-)

我的提示是使用ViewHolder模式,对于相同布局的大量项目(即使它是最简单的一个,例如单个TextView)

还有这个ViewHolder实现示例/库

此外,如果您在ListView项目布局中使用图像,则可以使用某些库异步下载图像,例如: