Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含很多变量(大约 1000 个)的列表视图。如何获取特定字符串变量的位置(例如“Washington”)?也就是说,我想说如何知道变量的名称(城市名称)来获得它在列表视图中的位置。
取决于ListAdapter你正在使用的。如果您有ArrayAdapter一个简单的字符串数组,则代码将类似于:
ListAdapter
ArrayAdapter
ArrayAdapter arrayAdapter = (ArrayAdapter) listView.getAdapter(); int position = arrayAdapter.getPosition("Washington");