Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid AutoComplete Binding Question
    primarykey
    data
    text
    <p>I'm developing an Android Recipe program which has database of food recipes. I have a created a database within it a table called "recipe" which has the following fields:</p> <p>1 - _id(referred to as KEY_ID)<br> 2 - recipe title(referred to as KEY_TITLE)<br> 3 - number of serves(referred to as KEY_NOSERV)<br> 4 - ingredients(referred to as KEY_INGREDIENT)<br> 5 - procedure(referred to as KEY_PROCEDURE)<br></p> <p>I have successfully implemented the display operation i.e I have done a listview which shows all the recipe titles and when I click on the title it shows me the remaining fields by extracting data from the database. In this method I could easily bind the data form database. The data binding logic which I used for this display operation is as follows which worked well.</p> <pre><code>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); </code></pre> <p>Right now I'm implementing the Search operation by using the AutoComplete Widget. The AutoComplete should show show only the recipe title. But in this I don't know how to bind the data in the AutoComplete box. I tried doing the same thing as I did in display operation but the app gets force closed. I have attached the xml and code samples as mentioned below. Please let me know as to how to do data binding to the AutoComplete Widget in this opearation.</p> <p><strong>res/layout File name : recipe_auto_list_item.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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"&gt; &lt;/TextView&gt; </code></pre> <p><strong>res/layout File Name:recipe_autocomplete.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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"&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="RECIPE NAME:" /&gt; &lt;AutoCompleteTextView android:id="@+id/autocomplete_recipe" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>The data binding logic which I used in the search activity is as follows:</p> <pre><code>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); </code></pre> <p>The fetchAllRecipes() functions extracts all the fields of the recipe table. from that I need to extract only the title and use in the autocomplete widget.</p> <p>When I try to start the search operation my app gets forced closed. Kindly what logic should I use for data binding.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload