3

我試圖實現AutoCompleteTextView來顯示自定義對象。因此,我實現了自己的ArrayAdapter,但它不起作用,當我在文本字段中輸入內容時沒有顯示任何建議。有人能幫我嗎?AutoCompleteTextView無法使用自定義ArrayAdapter

public class AutoCompleteArrayAdapter extends ArrayAdapter<Object>{ 

    List<Object> mObjectList; 
    Context mContext; 
    LayoutInflater mInflater; 
    int mResourceId; 

    public AutoCompleteArrayAdapter(Context context, int resource, List<Object> objectList) { 
     super(context, resource, objectList); 
     mResourceId = resource; 
     mObjectList = objectList; 
     mContext = context; 
     mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent){ 
     if(convertView == null) { 
      convertView = mInflater.inflate(mResourceId, parent, false); 
     } 

     Object object = mObjectList.get(position); 

     TextView textViewItem = (TextView) convertView.findViewById(R.id.textView_dropDown); 
     textViewItem.setText(object.getString()); 

     return convertView; 
    } 

    @Override 
    public int getCount() { 
     return mObjectList.size(); 
    } 

    @Override 
    public WordInfo getItem(int position) { 
     return mObjectList.get(position); 
    } 

    @Override 
    public long getItemId(int position) { 
     return position; 
    } 
} 

這裏我設置了適配器的主要活動:

AutoCompleteArrayAdapter adapter = new AutoCompleteArrayAdapter(this, R.layout.simple_textview, mAllWords); 
    mAutoEditTextSwedish.setAdapter(adapter); 

回答

相關問題