我是Android新手,正在製作音樂播放器應用程序。我在列表視圖中獲取第一個 行或歌曲標識,但我無法在列表視圖中獲取或檢索最後一個行標識。 listview包含多首歌曲,我需要獲取最後一首歌曲ID。如何獲取或檢索或獲取列表視圖中的最後一行或歌曲的ID?
我該如何取回?
我是Android新手,正在製作音樂播放器應用程序。我在列表視圖中獲取第一個 行或歌曲標識,但我無法在列表視圖中獲取或檢索最後一個行標識。 listview包含多首歌曲,我需要獲取最後一首歌曲ID。如何獲取或檢索或獲取列表視圖中的最後一行或歌曲的ID?
我該如何取回?
如果你使用Cursor填充數據,那麼你可以很容易地找到它.cursor.getcount()將給出記錄的總數。 如果條件適用。
int records = 0; // record will contain the counter for record
for(int i=0;i<cursor.getCount();i++) {
record = i;
if(records == cursor.getcount() {
// this will give the last record
}
}
定義的getItem()適配器的方法,以returrn歌曲條目(自定義結構或哈希映射/哈希表),並最後一個項目從適配器,使用取:
SongItem item=adapter.getItem(adapter.count()-1);
,並使用此項目獲取ID,專輯等
你是如何填充listview? – 2012-02-15 04:38:22