Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I found the solution to auto complete with listview displaying as below :-</p> <p>namelist.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;AutoCompleteTextView android:id="@+id/textView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="Search here" /&gt; &lt;ListView android:id="@+id/listView" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>SearchActivity.java</p> <pre><code>public class SearchActivity extends Activity { /** Called when the activity is first created. */ ListView listView; List&lt;String&gt; listItems=new ArrayList&lt;String&gt;(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.nameslist); // editTextSearch=(EditText)findViewById(R.id.editTextSearch); listView=(ListView)findViewById(R.id.listView); refreshList(""); } public void refreshList(String text) { listItems.clear(); DatabaseHandler db = new DatabaseHandler(this); List&lt;Contact&gt; mContactList= db.getAllContactsBySearch(""); for(int i=0;i&lt;mContactList.size();i++) { listItems.add(mContactList.get(i).getName()); } ArrayAdapter&lt;String&gt; adapter =new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_dropdown_item_1line, listItems); AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.textView); textView.setAdapter(adapter); } } </code></pre> <p>Databasehandler.java</p> <pre><code>// Getting All Contacts public List&lt;Contact&gt; getAllContactsBySearch(String searchStr) { List&lt;Contact&gt; contactList = new ArrayList&lt;Contact&gt;(); // Select All Query String selectQuery = "SELECT * FROM " + TABLE_CONTACTS + " where name LIKE '%"+searchStr+"%'"; SQLiteDatabase db = this.getWritableDatabase(); try { Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { Contact contact = new Contact(); contact.setID(Integer.parseInt(cursor.getString(0))); contact.setName(cursor.getString(1)); contact.setPhoneNumber(cursor.getString(2)); // Adding contact to list contactList.add(contact); } while (cursor.moveToNext()); } } catch(Exception e) { } // return contact list return contactList; } </code></pre> <p>Thanks!!I hope this will works.</p>
 

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