0
我創建了一個listview,它表明他標記了這個調用:view.setBackgroundResource(R.drawable.active_row) 但是當你向下滾動列表時,它會標記項目即低於lista.exe項目:當我向下滾動列表視圖項目被標記在列表下方
final ArrayList<HashMap<String, String>> songsListData = new ArrayList<HashMap<String, String>>();
SongsManager plm = new SongsManager();
// get all songs from sdcard
this.songsList = plm.getPlayList();
// 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
final ListAdapter adapter = new SimpleAdapter(this, songsListData,
R.layout.playlist_item, new String[] { "songTitle" }, new int[] {
R.id.songTitle2 });
setListAdapter(adapter);
ListView lv = getListView();
// listening to single listitem click
lv.setOnItemClickListener(new OnItemClickListener() {
int flag1 = 0;
int flag2 = 0;
int auxPosicao1 = -1;//primeira vez
int auxPosicao2 = -1;//primeira vez
@SuppressWarnings("unused")
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
View lastRow = null;
if (lastRow != null) {
lastRow.setBackgroundColor(0x00000000);
}
if (flag1==0 &&((auxPosicao1 == position || (auxPosicao1 == -1 && auxPosicao2==-1)))){
flag1 = 1;
auxPosicao1 = position;
aux = position;
view.setBackgroundResource(R.drawable.active_row);
}else if(auxPosicao1==position)
{
if (flag2 == 1){
aux = aux2;
auxPosicao1 = auxPosicao2;
aux2 = -1;
flag2 =0;
auxPosicao2 =-1;
}else{
aux = -1;
flag1=0;
auxPosicao1 =-1;
}
view.setBackgroundResource(R.drawable.active_row2);
}else if(flag2 == 0 &&((auxPosicao2 == position || auxPosicao2 == -1))){
aux2 = position;
view.setBackgroundResource(R.drawable.active_row);
flag2 = 1;
auxPosicao2 = position;
}else if(position == auxPosicao2){
aux2 = -1;
flag2 =0;
auxPosicao2 =-1;
view.setBackgroundResource(R.drawable.active_row2);
}else{
Toast.makeText(getBaseContext(), "Coming soon ...", Toast.LENGTH_SHORT).show();
}
//lastRow = view;
}
});
: 10項顯示在屏幕上,標記所述第一輥時在列表中向下,使得其示出了11,就好像它是第一個標記該項目11
... 我需要它來正確存儲我的列表狀態
你可以給我如何做到這一點的例子嗎? – 2014-09-21 17:04:32
發佈你的listadapter類 – 2014-09-21 17:05:58
編輯問題到ListAdapter ... – 2014-09-21 17:14:11