2012-02-23 38 views
1

您好,我是Android新手。我想將我的數據庫鏈接到自動完成文本視圖。我可以看到向下滾動列表,我可以從中選擇我的文本。但我用來檢索選定文本的getText()方法不起作用。我只讓我在文本框中鍵入和,所以我不能夠從給定的將SQLite鏈接到Android中的自動完成TextView?

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, getAllCountries()); 
     final AutoCompleteTextView input_text = (AutoCompleteTextView)findViewById(R.id.Language); 
     input_text.setAdapter(adapter); 
     Linkify.addLinks(input_text, Linkify.ALL); 
     Button button1=(Button)findViewById(R.id.button1); 
     final Editable name1=input_text.getText(); 

. 
. 
. 
public String[] getAllCountries() 
    { 
     Cursor cursor = db.rawQuery("SELECT * FROM colors ",null); 

       if(cursor.getCount() >0) 
     { 
      String[] str = new String[cursor.getCount()]; 
      int i = 0; 

      while (cursor.moveToNext()) 
      { 
       str[i] = cursor.getString(cursor.getColumnIndex("English")); 
       i++; 
      } 
      return str; 

     } 
     else 
     { 
      return new String[] {}; 
     } 
       } 

回答

0

我使用此代碼創建列表試試這個我的代碼database.please幫助me..snippet檢索:

String reciv ; 
    ArrayList<String> first = new ArrayList<String>(); 

cursor = dbm.columnValueofTable(); 
      cursor.moveToFirst(); 
      startManagingCursor(cursor); 

      for (int i = 0; i < cursor.getCount(); i++) { 

       reciv = cursor.getString(cursor 
         .getColumnIndex("row1")); 


       first.add(reciv); 

      } 

      System.out.println("LIST OF COURSE NAME " + first); 



      final String[] arrayOfStrings; 

      arrayOfStrings = first.toArray(new String[first.size()]); 


      AutoCompleteTextView lst = (AutoCompleteTextView ) dialog 
         .findViewById(R.id.dialog_list); 

       lst.setAdapter(new ArrayAdapter<String>(this, 
           android.R.layout.simple_list_item_1,android.R.id.text1, 
         arrayOfStrings)); 
相關問題