2013-12-08 64 views
0

helo, 我試圖在我的片段之一實現autocompletetextview,但我堅持。AutoCompleteTextView沒有顯示片段中的建議

問題是autocompletetextview不顯示建議。我可以從textview讀取適配器,但它仍然無法正常工作。

public class fragment_dodajpodroz extends Fragment { 

AutoCompleteTextView myAutoComplete; 
String item[]={ 
      "January", "February", "March", "April", 
      "May", "June", "July", "August", 
      "September", "October", "November", "December"}; 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 

    String DEBUG_TAG = "BAZA DANYCH"; 
    Context c = getActivity().getApplicationContext(); 


    View view = inflater.inflate(R.layout.dodajpodroz, container, false); 

    myAutoComplete = (AutoCompleteTextView)view.findViewById(R.id.autoCompleteTextView1); 


     ArrayAdapter<String> adapter = new ArrayAdapter<String> (c, android.R.layout.simple_dropdown_item_1line, item); 

     myAutoComplete.setAdapter(adapter); 



    return inflater.inflate(R.layout.dodajpodroz, container, false); 
} 
+0

,而不是'C'使用'getActivity()' – Raghunandan

+2

回報視圖,而不是dodajpodroz – pskink

+0

@pskink再膨脹 - 你的答案是偉大的! thans :) – tworzywohh

回答

1

見更正版本

@Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 

     String DEBUG_TAG = "BAZA DANYCH"; 
     Context c = getActivity().getApplicationContext(); 


     View view = inflater.inflate(R.layout.dodajpodroz, container, false); 

     myAutoComplete = (AutoCompleteTextView)view.findViewById(R.id.autoCompleteTextView1); 


     ArrayAdapter<String> adapter = new ArrayAdapter<String> (c, android.R.layout.simple_dropdown_item_1line, item); 

     myAutoComplete.setAdapter(adapter); 

     return view; 
    } 
+0

熱情,你能不能讓我看看你的XML自動完成佈局。我的項目出現錯誤。 http://stackoverflow.com/questions/32287402/android-autocomplettextview-resource-not-found-resource-is-not-a-drawable – Al2x

+0

資源不是可繪製的 - 意味着你應該檢查你的xml文件中的這一行android: popupBackground = 「@顏色/ wallet_highlighted_text_holo_dark」 – zest