我正在为 Android 制作一个销售点应用程序,并且我有一个 AutoCompleteTextView 加载了他们可以购买的商品数据库,但我也希望 AutoCompleteTextView 能够作为将自定义商品/注释添加到订单中的一种方式。
例如,客户点了牛排,但不需要任何调味料。我的数据库包含“无洋葱”“无蘑菇”等选项,但不包含“无调味料”,如果服务员在 AutoCompleteTextView 中输入“无调味料”,我希望弹出“添加为注释”建议。
有没有办法在没有找到其他建议时添加此建议,或者通过使其始终位于下拉列表中(使其无法被过滤掉),或者通过检测下拉列表中没有项目并将其添加到然后?
I am making a point of sale app for Android, and I have a AutoCompleteTextView loaded in with the database of items that they can buy, but I also want the AutoCompleteTextView to double as a way to add custom items/notes into the order.
So for example, the customer is ordering Steak, but doesnt want any seasoning. My database includes options for 'No Onions' 'No Mushrooms', etc, but not 'No Seasoning', and if the waiter types in 'No Seasoning' into the AutoCompleteTextView, I want a suggestion 'Add as Note' to pop up.
Is there a way to add this suggestion when no other suggestions are found, either by making it always on the dropdown list (making it not able to be filtered out), or by detecting when no items are on the dropdown list and adding it in then?
发布评论
评论(1)
我认为这可以使用 MatrixCursor 来完成。
当您从数据库中检索游标时,请使用 Cursor.moveToFirst() 检查其是否为空。然后用数据库光标填充 MatrixCursor 或单个“添加为注释”项(如果为空)。
我用它来将两个数据库游标合并为一个以获取建议 此处(方法 getUrlSuggestions(),最后一个)。请注意,这个示例不是很干净,因为所有值在插入 MatrixCursor 之前都被转换为 String。这不是必需的,因为 addRow() 方法采用对象数组。
I think this can be done using MatrixCursor.
When you retrieve the cursor from your database, check if its empty with Cursor.moveToFirst(). Then either fill the MatrixCursor with your database cursor or a single "Add as Note" item if empty.
I use this to combine two database Cursor in one for suggestions here (method getUrlSuggestions(), the last one). Note that this example is not very clean, as all values are casted to String before insertion in the MatrixCursor. This is not necessary as the addRow() method take an array of Object.