在我的應用程序中,我實現了ListView
。 現在我想它設置爲像這樣:如果我選擇特定指數,它應該保持爲選定。 ans顯示爲ListView
。 如果我選擇另一個索引,那麼現在新索引應該保持爲選定狀態。如何保持選中並突出顯示的listView索引?
編輯
意味着我要設置爲所選指數應繼續作爲選擇,直到我選擇另一所強調的。但不喜歡多選。
那麼怎麼辦呢?
請幫我了點。 我已經實現了ListView
像下面的代碼:
phonemesListView = (ListView) findViewById(R.id.phonemsListView);
private String[] Phonemes_List = new String[]{"P","B","T","D","K","G","N","M","ING","TH v","TH vl","F","V","S","Z","SH","CH","J","L","R rf","R b"};
phonemesListView.setAdapter(new ArrayAdapter<String>(this,R.layout.phonemes_list_row, R.id.phonemes,Phonemes_List));
@Override
public void onItemClick(AdapterView<?> parent, View view,final int Position,long id) {
phonemsText.setText(Phonemes_List[Position]);
Toast.makeText(getApplicationContext(), "Phonems: "+Phonemes_List[Position], Toast.LENGTH_SHORT).show();
// view.setBackgroundColor(Color.RED);
// phonemesListView.setBackgroundColor(Color.BLUE);
jumposition = Position;
int temp = 0;
if(jumpCount == -1){
view.setBackgroundColor(Color.BLUE);
jumpCount = jumposition;
JumpView = view;
temp = 1;
}
if(temp == 0) {
if(jumpCount == jumposition) {
view.setBackgroundColor(Color.BLUE);
JumpView = view;
}
else{
JumpView.setBackgroundColor(Color.TRANSPARENT);
view.setBackgroundColor(Color.BLUE);
jumpCount = jumposition;
JumpView = view;
}
}
}
感謝。
這篇文章可以給你一些有識之士http://stackoverflow.com/questions/3825645/android-listview-with-multiple-select-and-custom-adapter並嘗試listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); :) – 2012-01-17 12:43:48
@SergeyBenner:請參閱更新的問題。 – 2012-01-17 12:57:26