Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 根据SQLite表中选定的行和列值设置微调器的初始值_Android_Android Studio_Android Spinner - Fatal编程技术网

Android 根据SQLite表中选定的行和列值设置微调器的初始值

Android 根据SQLite表中选定的行和列值设置微调器的初始值,android,android-studio,android-spinner,Android,Android Studio,Android Spinner,我是android编程新手,因此对任何误用技术术语表示歉意。我有一个微调器,它的文本值为leagues\u name,id为id,来自leaguesSQLite表 leagues表设计示例 我还有一个teams表,用于存储团队信息,还有一个查找表,用于连接teams和leagues的id,该表名为teams\u vs\u leagues。因此,此微调器的选定值将插入到球队vs联赛表中的联赛id列中。我有一个编辑页面来编辑单个球队的记录,其中包括从微调器中选择联赛。但是,在本例中,它总是默认为第一

我是android编程新手,因此对任何误用技术术语表示歉意。我有一个微调器,它的文本值为
leagues\u name
,id为
id
,来自
leagues
SQLite表

leagues表设计示例 我还有一个
teams
表,用于存储团队信息,还有一个查找表,用于连接
teams
leagues
的id,该表名为
teams\u vs\u leagues
。因此,此微调器的选定值将插入到
球队vs联赛
表中的
联赛id
列中。我有一个编辑页面来编辑单个球队的记录,其中包括从微调器中选择联赛。但是,在本例中,它总是默认为第一个可用的
id
。尽管如此,我希望微调器的初始值是在与当前查看的
团队id
相对应的
团队id
中选择的
联盟id
。因此,如果选定的
球队id
联盟id
3
,我希望微调器的初始值为
Northern Division 2

UpdateTeam类 getAllLeagues方法
public ListgetAllLeagues(){
列表标签=新阵列列表();
//选择所有查询
String selectQuery=“SELECT*FROM”+联赛表;
SQLiteDatabase db=this.getReadableDatabase();
Cursor Cursor=db.rawQuery(selectQuery,null);
//循环遍历所有行并添加到列表
if(cursor.moveToFirst()){
做{
labels.add(新的联盟(cursor.getInt(0)、cursor.getString(1));
}while(cursor.moveToNext());
}
//闭合连接
cursor.close();
db.close();
//退回标签
退货标签;
}

如果您需要任何进一步的信息,请随时发表评论。任何帮助都将不胜感激。

将所选的league对象提供给数组适配器的getPosition()方法

int index = arrayAdapter.getPosition(SELECTED_LEAGUE_ID);
league.setSelection(index);

向数组适配器的getPosition()方法提供所选的league对象

int index = arrayAdapter.getPosition(SELECTED_LEAGUE_ID);
league.setSelection(index);

当我设置
int index=arrayAdapter.getPosition(String.valueOf(leagueId));联盟选举(指数)
我总是得到
1
的值,尽管如果我选择了一个值应该是
2
3
的团队,我很抱歉,当我设置
int index=arrayAdapter.getPosition(String.valueOf(leagueId)),我总是得到
-1
的值;联盟选举(指数)我总是得到一个值
1
,尽管我选择了一个值应为
2
3的团队,但我的道歉是,我总是得到一个值
-1
public class Leagues {

 //Declare Global String & int
 private int id;
 private String leagueName;

 /*********** Set Methods ******************/
 public Leagues(int id, String leagueName) {
  this.id = id;
  this.leagueName = leagueName;
 }

 public void setId(int id) {
  this.id = id;
 }

 public void setLeagueName(String leagueName) {
  this.leagueName = leagueName;
 }

 /*********** Get Methods ****************/
 public int getId() {
  return this.id;
 }

 public String getLeagueName() {
  return this.leagueName;
 }

 //Provides string value to display in Spinner
 @Override
 public String toString() {
  return leagueName;
 }
}
public List < Leagues > getAllLeagues() {
 List < Leagues > labels = new ArrayList < Leagues > ();
 // Select All Query
 String selectQuery = "SELECT  * FROM " + LEAGUES_TABLE;

 SQLiteDatabase db = this.getReadableDatabase();
 Cursor cursor = db.rawQuery(selectQuery, null);

 // looping through all rows and adding to list
 if (cursor.moveToFirst()) {
  do {
   labels.add(new Leagues(cursor.getInt(0), cursor.getString(1)));
  } while (cursor.moveToNext());
 }

 // closing connection
 cursor.close();
 db.close();

 // returning labels
 return labels;
}
int index = arrayAdapter.getPosition(SELECTED_LEAGUE_ID);
league.setSelection(index);