活动之间的共享游标

编程入门 行业动态 更新时间:2024-10-24 00:32:51
本文介绍了活动之间的共享游标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我觉得下面的情况是常见的,但我不明白的方式来实现它:

I think the following scenario is common, but I can't figure the way to implement it:

我们有三个活动,和一个数据库。我们询问用户的输入数据库中进行搜索。查询应该得到无,一个或可能的结果。

We have three Activities, and one database. We ask the user for an input to search in the database. The query should get none, one or may results.

  • 如果你没有,你简单的告知用户。
  • 如果你只有一个,你显示它与右视图一个新的活动。
  • 如果你得到很多你展示他们在一个列表,让用户来选择正确的,那么你传递到与显示数据的结果只有一个的情况下活动。

的问题在于,为了知道的结果数,就需要做查询(和得到的光标)在第一活性。而在情况下,你得到的不只是一个结果,你需要发送的数据(将光标移动?)到列表acitivty。在列表中活动的老毛病又犯了查询不可能是正确的,对吧?

The problem is that, in order to know the number of results, you need to do the query (and get the cursor) in the first activity. And in the case you get more than one result you need to send the data (pass the cursor?)to the list acitivty. Doing the query again in the list activity can't be right, right?

我知道,您可以通过使用内容提供商共享游标,但因为活动是从同一个应用程序和数据是私有的(无用外),看不出使得它的点avaliable给任何人

I'm aware that you can share cursors by using a content provider, but as the activities are from the same application and the data is private (useless outside), don't see the point of making it avaliable to anyone else.

我读到这里周围,你可以木箱一个parcelable光标,它捆绑发送,但我不知道这是正确的使用。

I read here around that you can crate a parcelable cursor and send it in bundle, but I'm not sure if that is the right use.

在如何解决这个任何想法?

Any idea on how to address this?

在此先感谢。

推荐答案

选项#1:搜索活动执行的查询就是 SELECT _ID FROM ...在无的情况下,它显示的信息。在一的情况下,它通过匹配的 _ID 到详细的活动通过查询来获得所需的所有列的一行查看本场比赛。在多的情况下,它通过搜索术语列表中的活动,它运行完整的查询(包括显示列表所需的所有列)。

Option #1: The query performed by the search activity is just SELECT _ID FROM... In the "none" case, it displays the message. In the "one" case, it passes the matching _ID to the detail activity to view the match by querying to get all needed columns for that one row. In the "many" case, it passes the search terms to the list activity, which runs the full query (including all columns needed to display the list).

选项2:合并的搜索活动和列表活动为一体的活动。基本上,认为搜索和选择项目以查看作为一个UI交易和一个活动中做的所有。搜索活动会做足够的填充在多案例列表中查询,显示列表中的 AlertDialog 或通过 ViewFlipper 什么的。在无的情况下,它显示的信息。在一的情况下 - 或当用户点击列表中的条目 - 它传递的东西的细节活动,以查看项目

Option #2: Merge the search activity and the list activity into one activity. Basically, consider "search and choose an item to view" as being a "UI transaction" and do that all within the one activity. The search activity would do a query sufficient to populate the list in the "many" case, displaying the list in an AlertDialog or in the main activity itself via a ViewFlipper or something. In the "none" case, it displays the message. In the "one" case -- or when the user taps an entry in the list -- it passes stuff to the detail activity to view the item.

选项#3:将您的搜索查询到列表中的活动 - 你的搜索活动,通过传递额外的搜索信息到列表中的活动,它执行 rawQuery()在的onCreate()。该列表活动处理了无与多的情况。在一的情况下,它只是调用 startActivity()的详细活动和完成()那么控制返回到搜索活动时,用户presses BACK。

Option #3: Move your search query to the list activity -- your search activity passes the search info to the list activity via extras, which does the rawQuery() in onCreate(). The list activity handles the "none" and "many" cases. In the "one" case, it just calls startActivity() on the detail activity and finish() so control returns to the search activity when the user presses BACK.

在其它条件相同,我可能会使用选项#去2。

All else being equal, I'd probably go with option #2.

更多推荐

活动之间的共享游标

本文发布于:2023-08-01 12:28:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1268333.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:游标

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!