gpt4 book ai didi

java - 如何获取Android中 ListView 中单击的项目的字符串值

转载 作者:行者123 更新时间:2023-12-02 09:44:34 26 4
gpt4 key购买 nike

这是我的数据库查询和 SimpleCursorAdapter 设置:

db = stockDatabaseHelper.getReadableDatabase();

final Cursor cursor = db.rawQuery("SELECT _id, name FROM types", null);

SimpleCursorAdapter listAdapter = new SimpleCursorAdapter(
this,
android.R.layout.simple_list_item_1,
cursor,
new String[] { StockDatabaseContract.StockType.COLUMN_NAME_NAME },
new int[] { android.R.id.text1 },
0);
lvTypes.setAdapter(listAdapter);

这是点击代码:

 AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(TypeSelection.this, BrandSelection.class);

String selectedType = parent.getItemAtPosition(position).toString();

intent.putExtra(BrandSelection.TYPE_NAME, selectedType);
startActivity(intent);
}
};

我似乎只得到一个值,例如 android.database.sqlite.SQLiteCursor@435b9ba0但只需要列表中项目的值(value),例如伏特加或威士忌

最佳答案

在你的 onclick 监听器中:

cursor.moveToPosition(position);
String drinkString = cursor.getString(cursor.getColumnIndexOrThrow(" *column name* "));

关于java - 如何获取Android中 ListView 中单击的项目的字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56764733/

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