Android自动完成绑定问题

问题描述:

我正在开发一个Android食谱程序,其中有食谱的数据库。我已创建的数据库中它称为它具有下列字段“配方”的表:Android自动完成绑定问题

1 - _id(简称KEY_ID)
2 - 配方标题(简称KEY_TITLE)
3 - 数成分(被称为KEY_INGREDIENT)
5 - - 发球(简称KEY_NOSERV)
4的过程(称为KEY_PROCEDURE)

我已经成功地实施了显示操作即我已完成列表视图,其示出了所有的食谱标题,当我点击标题时,它会显示剩余的字段通过从数据库提取数据。在这种方法中,我可以轻松地绑定数据表单数据库。我用于此显示操作的数据绑定逻辑如下,运行良好。

Cursor c = rDbHelper.fetchAllRecipes(); 
     startManagingCursor(c); 

     String[] from = new String[] { RecipeDbAdapter.KEY_TITLE }; 
     int[] to = new int[] { R.id.text1 }; 

     SimpleCursorAdapter recps = 
      new SimpleCursorAdapter(this, R.layout.recipe_row, c, from, to); 

     setListAdapter(recps); 

现在我正在使用AutoComplete Widget实现搜索操作。自动完成应该只显示只显示配方标题。但在这我不知道如何绑定自动完成框中的数据。我尝试了与我在显示操作中做的相同的事情,但是应用程序被强制关闭。我已经附加了如下所述的xml和代码示例。请让我知道如何在此操作中对数据绑定到AutoComplete Widget。

RES /布局文件名:recipe_auto_list_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/textautocomplete" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="10dp" 
    android:textSize="16sp" 
    android:textColor="#000"> 
</TextView> 

RES /布局文件名:recipe_autocomplete.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:padding="5dp"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="RECIPE NAME:" /> 
    <AutoCompleteTextView android:id="@+id/autocomplete_recipe" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="5dp"/> 
</LinearLayout> 

数据绑定我在搜索中使用的逻辑活动如下:

super.onCreate(savedInstanceState); 
setContentView(R.layout.recipe_autocomplete); 

AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_recipe); 

Cursor c = rDbHelper.fetchAllRecipes(); 
     startManagingCursor(c); 

     String[] from = new String[] { RecipeDbAdapter.KEY_TITLE }; 
     int[] to = new int[] { R.id.textautocomplete }; 

     SimpleCursorAdapter cur = new SimpleCursorAdapter(this, R.layout.recipe_auto_list_item, c, from, to); 
textView.setAdapter(cur); 

fetchAllRecipes()函数提取配方表的所有字段。从那我需要提取只有标题和在自动填充小部件中使用。

当我尝试启动搜索操作时,我的应用程序被强制关闭。请使用什么逻辑来进行数据绑定。

为什么不尝试使用Search feature withing Android