2011-12-28 5 views
0

私は連絡先リストを持っています。私のリストに検索を行いたいときは、autocompletetextビューを使用したいのですが、それは動作しません。autocompletetextviewが機能しない

オートコンプリートテキストビューで入力を開始しても何も表示されませんが、検索ボタンをクリックすると、私は必要な連絡先を見つけます。ここ

は私の.javaです:ここ

  public class Search extends ListActivity { 
     private static int[] TO = {R.id.rowid,R.id.name, R.id.mobilephone, R.id.email }; 
private static String[] FROM = {_ID,DbConstants.NAME, DbConstants.PHONE, DbConstants.EMAIL, }; 
private Button sButton; 

private ListView lv1; 
private static SQLiteDatabase db; 
    private DbCreate contacts; 
    private Cursor cursor; 
    private EditText searchText; 
    protected SimpleCursorAdapter adapter; 


      protected void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.search); 
    searchText=(EditText)findViewById(R.id.searchtext); 
    sButton=(Button)findViewById(R.id.searchButton); 
    sButton.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      showDatabaseContent(); 
       lv1 = getListView(); 

       lv1.setTextFilterEnabled(true); 
     } 
    }); 





       } 


       private Cursor getContacts() { 
     db = contacts.getReadableDatabase(); 
     cursor = db.rawQuery("SELECT _id,name, phone, email FROM contactTest1 WHERE name LIKE ?", 
       new String[]{searchText.getText().toString()+"%"}); 
     startManagingCursor(cursor); 
     return cursor; 
        } 

        public void showDatabaseContent(){ 
    contacts = new DbCreate(this); 
    try { 
     cursor = getContacts(); 
     showContacts(cursor); 
    } finally { 
     contacts.close(); 
     db.close(); 
       } 
       } 

         private void showContacts(Cursor cursor) { 
    //set up data binding 
    adapter = new SimpleCursorAdapter(this, R.layout.item, cursor, FROM, TO); 
    setListAdapter(adapter); 
      } 

         public void onListItemClick(ListView parent, View v, int position, long id) { 
    Intent abaintent = new Intent(this,Detalii.class); 
    Cursor cursor = (Cursor) adapter.getItem(position); 
    abaintent.putExtra("Contact_ID", cursor.getInt(cursor.getColumnIndex("_id"))); 
    startActivity(abaintent); 
} 

}

は私search.xmlです:

  <?xml version="1.0" encoding="utf-8" ?> 
      <LinearLayout xmlns:android="http://schemas.android.com/apk//android"   

      android:orientation="vertical" 
      android:layout_width="fill_parent"   
      android:layout_height="fill_parent"> 
       <LinearLayout 
      android:orientation="horizontal" 
       android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 


      <AutoCompleteTextView 
    android:id="@+id/searchtext" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="searchDefault" > 

    <requestFocus /> 
</AutoCompleteTextView> 
      <Button android:id="@+id/searchButton" 
      android:text="Search" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
      </LinearLayout> 
       <ListView 
      android:id="@android:id/list" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" /> 

     </LinearLayout> 

答えて

0

あなたはそこ

android:layout_weight="1" 

を持っていないのはなぜ? 私はそれを削除します。

+0

これは問題ではありません – jonny

関連する問題