1
我已經創建了列表視圖,我想在我的列表視圖中實現sectionindexer和alphabetIndexer。 我正在嘗試http://www.anddev.org/tutalphabetic_fastscroll_listview_-_similar_to_contacts-t10123.html。這很好。但對於我的代碼,我沒有得到如何實現該功能。在Android的列表視圖中顯示字母索引
這裏是我的list_item.xml代碼:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:background="@drawable/list_selector"
android:padding="5dp"
android:id="@+id/tab">
<LinearLayout android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip">
<ImageView
android:id="@+id/list_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="@drawable/musicsymbol"/>
</LinearLayout>
<TextView
android:id="@+id/songTitle"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:textSize="16dp"
android:textColor="#ffffff"
android:textStyle="bold"
android:layout_alignTop="@+id/thumbnail"
android:color="#10bcc9"
android:maxLines="1"
android:layout_toRightOf="@+id/thumbnail"
/>
<TextView
android:id="@+id/duration"
android:layout_width="56dip"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/songTitle"
android:gravity="right"
android:layout_marginRight="5dip"
android:textSize="15dip"
android:textColor="#10bcc9"
android:textStyle="bold"
android:maxLines="1"
/>
<TextView
android:id="@+id/songArtist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/songTitle"
android:textSize="14dp"
android:color="#10bcc9"
android:textStyle="bold"
android:lines="1"
android:layout_toRightOf="@+id/thumbnail"
/>
我的Java代碼:
Cursor cursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,null , null, null,MediaStore.Audio.Media.TITLE);
if (cursor == null)
{
//Query Failed , Handle error.
}
else if (!cursor.moveToFirst())
{
//No media on the device.
}
else
{
int titleColumn = cursor.getColumnIndex(android.provider.MediaStore.Audio.Media.TITLE);
int idColumn = cursor.getColumnIndexOrThrow(android.provider.MediaStore.Audio.Media.DATA);
int artistcolumn = cursor.getColumnIndex(android.provider.MediaStore.Audio.Media.ARTIST);
int durationcolumn =cursor.getColumnIndex(android.provider.MediaStore.Audio.Media.DURATION);
for(int i=0;i<cursor.getCount();i++)
{
String thisTitle = cursor.getString(titleColumn);
String path = cursor.getString(idColumn);
String artist = cursor.getString(artistcolumn);
Long duration = cursor.getLong(durationcolumn);
Utilities objUtilities = new Utilities();
String timeDuration = objUtilities.milliSecondsToTimer(duration);
HashMap<String, String> song = new HashMap<String, String>();
song.put("songTitle",thisTitle);
song.put("songPath", path);
song.put("artist", artist);
song.put("duration",timeDuration);
// Adding each song to SongList
songsList.add(song);
cursor.moveToNext();
}
}
// looping through playlist
for (int i = 0; i < songsList.size(); i++) {
// creating new HashMap
HashMap<String, String> song = songsList.get(i);
// adding HashList to ArrayList
songsListData.add(song);
}
// Adding menuItems to ListView
String[] from = {"songTitle", "artist" , "duration"};
int[] to={R.id.songTitle,R.id.songArtist, R.id.duration};
adapter = new SimpleAdapter(this, songsListData,
R.layout.playlist_item, from, to);
setListAdapter(adapter);
所以如何實現我的這個listadapter sectionindexer。請給我一些解決方案。感謝名單。
Thanx.But,它是部分索引器的一個例子,我想用AlphabetIndexer的sectionIndexer。 – zanky