Android UI--开源项目IndexableListView(字母索引),Android最新实习面试经验总结

本文介绍了Android开源项目IndexableListView的实现,展示了如何在ListView中添加字母索引功能。同时,文章还分享了Android实习面试的经验总结,强调了对Android知识点掌握的全面性和深入性对于面试的重要性。
摘要由CSDN通过智能技术生成

android:layout_height=“fill_parent”

android:id="@+id/listview" />

Activity

package com.woozzu.android.indexablelistview;

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

import android.app.Activity;

import android.content.Context;

import android.os.Bundle;

import android.widget.ArrayAdapter;

import android.widget.SectionIndexer;

import com.woozzu.android.util.StringMatcher;

import com.woozzu.android.widget.IndexableListView;

public class IndexableListViewActivity extends Activity {

private ArrayList mItems;

private IndexableListView mListView;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

// 初始化一些数据

mItems = new ArrayList();

mItems.add(“Diary of a Wimpy Kid 6: Cabin Fever”);

mItems.add(“Steve Jobs”);

mItems.add(“Inheritance (The Inheritance Cycle)”);

mItems.add(“11/22/63: A Novel”);

mItems.add(“The Hunger Games”);

mItems.add(“The LEGO Ideas Book”);

mItems.add(“Explosive Eighteen: A Stephanie Plum Novel”);

mItems.add(“Catching Fire (The Second Book of the Hunger Games)”);

mItems.add(“Elder Scrolls V: Skyrim: Prima Official Game Guide”);

mItems.add(“Death Comes to Pemberley”);

mItems.add(“Diary of a Wimpy Kid 6: Cabin Fever”);

mItems.add(“Steve Jobs”);

mItems.add(“Inheritance (The Inheritance Cycle)”);

mItems.add(“11/22/63: A Novel”);

mItems.add(“The Hunger Games”);

mItems.add(“The LEGO Ideas Book”);

mItems.add(“Explosive Eighteen: A Stephanie Plum Novel”);

mItems.add(“Catching Fire (The Second Book of the Hunger Games)”);

mItems.add(“Elder Scrolls V: Skyrim: Prima Official Game Guide”);

mItems.add(“做作”);

mItems.add(“wokao”);

Collections.sort(mItems); // 排序

ContentAdapter adapter = new ContentAdapter(this,

android.R.layout.simple_list_item_1, mItems);

mListView = (IndexableListView) findViewById(R.id.listview);

mListView.setAdapter(adapter);

mListView.setFastScrollEnabled(true); // 设置快速滑动

}

private class ContentAdapter extends ArrayAdapter implements

SectionIndexer {

private String mSections = “#ABCDEFGHIJKLMNOPQRSTUVWXYZ”;

public ContentAdapter(Context context, int textViewResourceId,

List objects) {

super(context, textViewResourceId, objects);

}

@Override

public int getPositionForSection(int section) {

// If there is no item for current section, previous section will be

// selected

// 如果当前部分没有item,则之前的部分将被选择

for (int i = section; i >= 0; i–) {

for (int j = 0; j < getCount(); j++) {

System.out.println(getCount());

if (i == 0) { // #

// For numeric section 数字

for (int k = 0; k <= 9; k++) {// 1…9

// 字

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值