gpt4 book ai didi

java - 为什么我得到 "mergeCursor"对象而不是 "string"?

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

当我执行下面的代码时,我想得到 text="All" ,因为它的可见值(value)就是这样,但我一直在得到

String text = "android.database.MergeCursor@88a4aaa"

代码:

String[] from = new String[]{"type"};
int[] to = new int[]{android.R.id.text1};
Cursor cursorTypes = coctelsOpenHelper.getTypes();
//Add "All" option to the spinner
MatrixCursor matrixCursor = new MatrixCursor(new String[] { "_id", "type"});
matrixCursor.addRow(new Object[] { "0", getString(R.string.title_all_drinks) });

MergeCursor mergeCursor = new MergeCursor(new Cursor[] { matrixCursor, cursorTypes });

spinnerType = view.findViewById(R.id.spinnerDrinkType);
adapter = new SimpleCursorAdapter(getContext(), android.R.layout.simple_spinner_item, mergeCursor, from, to,0);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerType.setAdapter(adapter);

spinnerType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
//When I try to debug, the text value is the given above, a MergeCursor
text = ((String)spinnerType.getSelectedItem().toString());

selectedItem = position;
addSelection();
//This ones don't have anything in common with the adapter from the spinner, are for a RecyclerView
initializeData();
initializeAdapter();
}
public void onNothingSelected(AdapterView<?> parent)
{
}
});

不,“文本”不再被使用,所以它的值没有改变,我也尝试过

spinnerType.getSelectedItem().toString();

但得到了相同的结果。

我想做的就是获取 Spinner 上文本的字符串值,并将其与 R.string.myvalue 进行比较与 text.equals(getString(R.string.myvalue))

最佳答案

你的变量的类型是什么?

关于java - 为什么我得到 "mergeCursor"对象而不是 "string"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60059876/

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