gpt4 book ai didi

java - 如何从 Spinner 获取客户 ID

转载 作者:太空宇宙 更新时间:2023-11-04 11:10:19 24 4
gpt4 key购买 nike

这是我从数据库中为微调器调用客户名称的函数。当我选择客户名称时,我还可以获得客户 ID。怎么做?

 public List<String> getAllUsers(String userID) {
List<String> userlist = new ArrayList<>();
String status= "Active";
SQLiteDatabase db = this.getReadableDatabase();
String query = "select " + COLUMN_Customer_NAME + " from customer where " + COLUMN_Customer_USERID + "='" + userID + "'"+" AND " + COLUMN_Customer_STATUS + "='" + status + "'";
Cursor cursor = db.rawQuery(query, null);
if (cursor.moveToFirst()) {
do {
userlist.add(cursor.getString(0));
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return userlist;

}

最佳答案

spinner_province.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String item = parent.getItemAtPosition(position).toString();
province_id = position;
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
});

通过使用它,您可以从微调器中获取选定的项目。

关于java - 如何从 Spinner 获取客户 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46090849/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com