2014-12-03 32 views
0

爲什麼它不顯示任何自動更正我的數組有串自動完成文本視圖不工作

AlertDialog.Builder alert = new AlertDialog.Builder(this); 

alert.setTitle("Sentence"); 
alert.setMessage("type only words you taught him!!!"); 

// Set an EditText view to get user input 
//final EditText input = new EditText(this); 
//alert.setView(input); 
// Get a reference to the AutoCompleteTextView in the layout 
final AutoCompleteTextView textView = new AutoCompleteTextView(this); 
// Get the string array 
//String[] countries = getResources().getStringArray(R.array.countries_array); 
// Create the adapter and set it to the AutoCompleteTextView 
ArrayAdapter<String> adapter = 
     new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mywords); 
textView.setAdapter(adapter); 
alert.setView(textView); 
alert.setPositiveButton("Order", new DialogInterface.OnClickListener() { 
public void onClick(DialogInterface dialog, int whichButton) { 
    String value =textView.getText().toString(); 

    String[] inputarray; 
    value=value.trim(); 
    inputarray=value.split(" "); 
    playnum=new int[inputarray.length]; 
     for(int j=0;j<inputarray.length;j++) 
     { 
      legit=0; 
      for(int i=0;i<mywords.length;i++) 
      { 
      if(info.choosetext[Integer.parseInt(mywords[i])].equalsIgnoreCase(inputarray[j])){ 
       playnum[j]=Integer.parseInt(mywords[i]); 
      legit++; 
      } 
      } 
      if(legit==0) 
       break; 

     } 





     if(legit!=0){  
      playone=MediaPlayer.create(getBaseContext(), getResources().getIdentifier("word" + Integer.toString(playnum[0]), "raw", getPackageName())); 
     gottext=true; 
     } 
    } 
}); 

alert.setNegativeButton("Dismiss", new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int whichButton) { 
    // Canceled. 
    } 
}); 

alert.show(); 

我希望它顯示陣列的建議和點擊它輸入到文本視圖,現在我說只是因爲我有太多的代碼並不能張貼

有其他人知道如何做到這一點沒有XML

+0

我乞求幫助,我不在XML是在這個 – learning 2014-12-03 16:54:42

回答

0

至少有一件事你應該做的是在聲明XML自動完成文本視圖,並得到一個參考致電AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.textView);而不是final AutoCompleteTextView textView = new AutoCompleteTextView (this)

這裏是自動完成的文本視圖一個很好的教程: http://www.tutorialspoint.com/android/android_auto_complete.htm

+0

我的新佈局後的一個Java佈局 – learning 2014-12-03 23:49:02

0

試試這個, textview.setThreshold(1); textview.setAdapter()

+0

試圖d它仍然沒有文字warting作品,但不建議 – learning 2014-12-04 08:36:43

+0

我開始認爲它不可能裏面警報butt edittext自動更正作品 – learning 2014-12-04 08:43:14

+0

注意到,如果我離開單擊全局字典仍然存在(左鍵單擊文本,我從全局字典中得到建議) – learning 2014-12-04 08:49:47