Android Listview查找特定项目并默认选择
我想在列表中找到一个特定项目,并在默认情况下将其选中。如果我能找到位置,我可以调用Android Listview查找特定项目并默认选择,android,android-listview,Android,Android Listview,我想在列表中找到一个特定项目,并在默认情况下将其选中。如果我能找到位置,我可以调用ListView.setItemSelected(位置,true) 我正在使用SimpleCursorAdapter来显示类别列表,这可以动态更改,所以我不能只找到索引和硬代码 如何在不使用OnClickListener的情况下通过字符串查找列表项的位置?如果不查看代码,很难说什么最适合您的实现,但可能是像这样的实现 SimpleCursorAdapter myAdapter; ... //search here
ListView.setItemSelected(位置,true)
我正在使用SimpleCursorAdapter来显示类别列表,这可以动态更改,所以我不能只找到索引和硬代码
如何在不使用OnClickListener的情况下通过字符串查找列表项的位置?如果不查看代码,很难说什么最适合您的实现,但可能是像这样的实现
SimpleCursorAdapter myAdapter;
...
//search here
int count = myAdapter.getCount();
for(int i=0; i < count; i++){
if("desired string".equals(myAdapter.getItem()){
listView.setItemSelected(i, true);
}
}
SimpleCursorAdapter myAdapter;
...
//在这里搜索
int count=myAdapter.getCount();
for(int i=0;i
我想您不需要在ListView中查找,而需要在列表或字符串[]中查找,您可以使用它来填充数据并查找数据索引,并将特定项设置为选中项