我有一个 ListView ,我需要以编程方式突出显示一个项目。
我试过这个:
CalendarList = (ListView) findViewById(R.id.CalendarList);
CalendarList.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, MyApplication.roundMatches(CalendarPicker.getValue())));
CalendarList.setSelection(2);
但是 setSelection 不起作用。
最佳答案
要在触摸模式下突出显示项目,您必须首先调用 CalendarList.requestFocusFromTouch();然后 CalendarList.setSelection(2);
在触摸模式下,setSelection() 本身不起作用。
关于android - 如何以编程方式突出显示 ListView 的项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6797493/