我有一个从数据库中填充的微调器。我想选择默认选择列表中的哪个项目。我需要找出列表(CursorAdapter)中的哪个项目具有“默认离开”值并将其设置为所选值。
Spinner away_team_spinner = (Spinner)findViewById(R.id.away_team_spinner);
DatabaseHelper db = new DatabaseHelper(this);
Cursor team_list = db.getTeams(p_game_level);
startManagingCursor(team_list);
String[] team_name = new String[]{colTeamName};
int[] to = new int[]{android.R.id.text1};
SimpleCursorAdapter adapter =
new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, team_list, team_name, to );
adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
away_team_spinner.setAdapter(adapter);
//// HERE IS WHERE MY ERRORS START ////
Log.i("NEW_GAME","Before set arrayadapter");
CursorAdapter adapter_choose = (CursorAdapter)away_team_spinner.getAdapter();
Log.i("NEW_GAME","Before set setSelection");
away_team_spinner.setSelection(adapter_choose.getPosition("Default Away"));
这是我在这个网站上搜索找到的“解决方案”。但是,我不能将“getPosition”与 CursorAdapter 对象一起使用。我尝试了 ArrayAdapter,但是在“设置 arrayadapter 之前”之后的行注释错误“android.widget.SimpleCursorAdapter 无法转换为 android.widget.ArrayAdapter”。我究竟做错了什么?谢谢。