In My app i have implement the ListView.
Now i want it to set as like that: If i select on perticular index it should be remain as selected. ans appear as selected on ListView.
If i select another index then now that new index should be remain as selected.
Edited
Means I want to set as the selected index should remain as highlighted as selected till I select another. but not like multiple selected.
So how to do it ?
Please help me for that.
I have implemented the ListView as like below code:
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;
}
}
}
Thanks.
You can just save the selected position from the data holder that you are using to populate your ListView. Then, you can use
setSelection(position)attribute of ListView to set the selected position remain selected whenever you want.