在Android中搜寻

在Android中搜寻,第1张

概述我有一个想要在其中添加搜索功能的应用程序,我试图按照developer.android中的说明实施,但是当我在模拟器中单击搜索时,活动没有开始,这是什么问题?>SearchActivity.javapublicclassSearchActivityextendsListActivity{publicvoidonCreate(BundlesavedInstanceState)

我有一个想要在其中添加搜索功能的应用程序,我试图按照developer.android中的说明实施,但是当我在模拟器中单击搜索时,活动没有开始,这是什么问题?

> SearchActivity.java

public class SearchActivity extends ListActivity {  public voID onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);   handleIntent(getIntent());} @OverrIDe public voID onNewIntent(Intent intent) {   super.onNewIntent(intent);   setIntent(intent);   handleIntent(intent); } public voID onListItemClick(ListVIEw l,   VIEw v, int position, long ID) {    // call detail activity for clicked entry } private voID handleIntent(Intent intent) {  if (Intent.ACTION_SEARCH.equals(intent.getAction())) {  String query =intent.getStringExtra(SearchManager.query);   doSearch(query); }}  private voID doSearch(String queryStr) {    // get a Cursor, prepare the listadapter    // and set it }}

> xml / searchable.xml

<?xml version="1.0" enCoding="utf-8"?><searchable xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:label="@string/app_name"    androID:hint="@string/srchHint"    androID:inputType="textCapCharacters"></searchable>

> AndroIDManifest.xml(下面的代码不显示其他活动)

<application>     <!-- other actvitIEs -->      <activity androID:label="@string/app_name" androID:launchMode="singletop"              androID:name=".SearchActivity">        <intent-filter>            <action androID:name="androID.intent.action.SEARCH" />      </intent-filter>        <Meta-data androID:name="androID.app.searchable" androID:resource="@xml/searchable" />     </activity></application>

已经尝试过的事情:

1.在StackOverflow上查看类似的问题及其解决方案

2.查看grokkingandroid和edumobile的教程,它们对我的问题没有帮助.

3.花时间在chat.stackoverflow上问人

问题/问题

1.好吧,我有doSearch()方法,但是如何精确地触发查询以及如何显示db的结果(以一个小db来显示示例,如何尽可能准确地显示结果).

2.当我单击模拟器中的搜索时,搜索活动不会开始.

3.在设计搜索时要牢记的一点是,除了developer.androID内容外,网站上很多时候都没有透露其他细节.

4.如何执行全文搜索,我在developer.androID上了解到它,如何让我的数据库更好地拥有FTS

附注:我是初学者,因此如果有菜鸟错误,请耐心等待,不要跳过任何步骤.

解决方法:

因此,搜索是决定您的应用程序实际可用性的关键因素,并提供必要的用户增强功能

1.这是处理搜索最简单的方法之一

private voID handleIntent(Intent intent) {       if (Intent.ACTION_SEARCH.equals(intent.getAction())) {          String query =                intent.getStringExtra(SearchManager.query);          doSearch(query);       }    }       private voID doSearch(String queryStr)        {        // get a Cursor/ArrayList, prepare the listadapter       // and set it       //helper.getSearchRecords(queryStr);//helper is a sqliteOpenHelper Object       //set it to adapter or get return result and proceed as you wish       //personally i prefer ArrayAdapter       ListVIEw lstResult=(ListVIEw)findVIEwByID(R.ID.lstVwResult);       lstResult.setAdapter(null);    SearchAdapter adapter=new SearchAdapter(getApplicationContext(), R.ID.txvPersonID, helper.getSearchRecords(queryStr));        lstResult.setAdapter(adapter);   } 

2. SearchActivity无法启动的原因是< Meta-data>.同样需要在活动之外定义

<application><activity androID:label="@string/app_name" androID:launchMode="singletop"                  androID:name=".SearchActivity">            <intent-filter>                <action androID:name="androID.intent.action.SEARCH" />            </intent-filter>            <Meta-data androID:name="androID.app.searchable"  androID:resource="@xml/searchable" /></activity><!--define Metadata outsIDe activity in application tag--><Meta-data androID:name="androID.app.default_searchable" androID:value=".SearchActivity" />

3.要记住的关键事项之一,为什么要向应用程序中添加搜索功能,它是一个“联系人”应用程序,单击“检索结果”将显示特定联系人的更多详细信息,但是对于餐厅应用程序,它将显示以下详细信息在餐厅的详细信息中,您(开发人员)应该开发它来满足用户需求并增强用户体验.

4.进行全文搜索并非总是必要的,它完全取决于您希望如何向db查询结果,您将考虑哪些字段以及它们与应用程序的主要目的如何相关,

更多参考

> Sqlite.org(这是《 HOW and What》的最广泛的文章,
FTS).
> blog.andresteingress(带有AndroID教程的FTS).
> O Reilly.

总结

以上是内存溢出为你收集整理的在Android中搜寻全部内容,希望文章能够帮你解决在Android中搜寻所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1094610.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存