【发布时间】:2012-01-17 12:41:26
【问题描述】:
在我的应用程序中,我实现了ListView。
现在我希望它像这样设置:如果我在特定索引上选择它应该保持选中状态。 ans 在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;
}
}
}
谢谢。
【问题讨论】:
-
这篇文章可以给你一些见解stackoverflow.com/questions/3825645/… 并尝试 listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); :)
-
@SergeyBenner :请查看更新后的问题。
标签: android listview android-layout android-listview expandablelistview