【问题标题】:Show letter-preview when scrolling list滚动列表时显示字母预览
【发布时间】:2011-07-26 02:00:50
【问题描述】:

Lista 是使用通过我的数据库数组收集的数据制作的。我想在滚动 A-Ö 列表时显示字母预览。我该怎么做?谢谢...

public class L extends BaseActivity {

    private ListView m_listView;
    private DBManager m_db;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.letters);
        customizeTitleBar("A-Ö", null);
        setVisibilityToButton(R.id.left_button, visibilityGone);
        setVisibilityToButton(R.id.right_button, visibilityGone);

        m_db = new DBManager(getApplicationContext());
        m_db.openDataBase();

        m_listView = (ListView)findViewById(R.id.letters_listview);
        m_listView.setFastScrollEnabled(true);

        final ArrayList<Image> words = m_db.selectAllWords();

        WordListAdapter adapter = new WordListAdapter(getApplicationContext(), words);

        m_listView.setAdapter(adapter);

        m_listView.setOnItemClickListener(new OnItemClickListener(){

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                Intent intent = new Intent(getApplicationContext(), ShowImage.class);

                intent.putExtra("selectedItem", words.get(arg2).getRowId());
                intent.putExtra("word", words.get(arg2).getWord());

                startActivity(intent);
            }
        });
        m_db.closeDatabase();
    }
}

适配器是:

public class Adapter extends BaseAdapter {


    private LayoutInflater m_inflater;
    private ArrayList<Image> m_data = new ArrayList<Image>();
    ImageHelper m_helper = new ImageHelper();

    public Adapter(Context context, ArrayList<Image> data){
        this.m_inflater = LayoutInflater.from(context);
        this.m_data= data;
    }

    public int getCount() {
        return this.m_data.size();
    }

    public Image getItem(int position) throws IndexOutOfBoundsException{
        return this.m_data.get(position);
    }

    public long getItemId(int position) throws IndexOutOfBoundsException{
        if(position < getCount() && position >= 0 ){
            return position;
        }
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent){

        if(convertView == null){
            convertView = this.m_inflater.inflate(R.layout.lettersrows, null);
        }

        TextView tv = (TextView)convertView.findViewById(R.id.label);

        tv.setText(this.m_data.get(position).getWord());
        tv.setTextSize(25);  

        convertView.setBackgroundColor((position & 1) == 1 ? Color.WHITE : Color.LTGRAY);

        return convertView;
    }
}

【问题讨论】:

    标签: android arrays list overlay


    【解决方案1】:

    我知道你问已经有一段时间了,但你必须让你的适配器实现 SectionIndexer 以在你快速滚动时显示字母。这是一个很好的例子,你可以看看需要做什么。

    http://twistbyte.com/tutorial/android-listview-with-fast-scroll-and-section-index

    【讨论】:

      【解决方案2】:

      您可能希望在 ListView 上设置“setFastScrollEnabled(boolean)”。

      【讨论】:

      • 不,没问题。我想查看 list9(api 演示,数组叠加)。谢谢
      猜你喜欢
      • 1970-01-01
      • 2015-09-28
      • 1970-01-01
      • 2019-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-25
      • 2013-10-14
      相关资源
      最近更新 更多