AlertDialog Builder中的AutoCompleteTextView

时间:2014-10-24 13:14:30

标签: android alertdialog autocompletetextview

我试图解决这个问题,但没有任何内容出现在我脑海中,以下代码是具有电影的应用程序的一部分,如果我单击搜索按钮,它会创建一个带有AutoCompleteTextView的对话框构建器,用于键入名称电影。

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(new ContextThemeWrapper(ThisScreen.search_context, android.R.style.Theme_Black));          
            ///// autocomplete thingie
            String[] name_mov = new String[movie_categ.size()];
            name_mov = movie_categ.toArray(name_mov);           

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

            LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            final View search_View = inflater.inflate(R.layout.this_movie_search, null);            

            myAutoComplete = (AutoCompleteTextView)
                    search_View.findViewById(R.id.movie_name);      

            myAutoComplete.setAdapter(adapter);
            myAutoComplete.setThreshold(2);

            /////               
            alertDialogBuilder.setView(searchView);
            alertDialogBuilder.setOnCancelListener(new OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    isFirstDialog = 0;                  
                }
            });
            alertDialog = alertDialogBuilder.create();  

            if (movie_categ.isEmpty() ) 
            {
                Toast.makeText(ThisScreen.search_context, "Verify net conn.", Toast.LENGTH_LONG).show();
                isFirstDialog = 0;
            }
            else alertDialog.show();

和this_movie_search.xml有

  <AutoCompleteTextView
      android:id="@+id/movie_name"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_toLeftOf="@+id/button_search"
      android:textColorHint="@android:color/white"
      android:hint="@string/search_hint"
      android:ems="10"
      android:maxLength="50"
      />

带有建议的列表没有出现,任何想法为什么?

1 个答案:

答案 0 :(得分:0)

我搜索答案的时间太长而且没有看到明显的答案,我应该从头开始声明我的myAutoComplete为'AutoCompleteTextView'类型,并且它有效。

   final AutoCompleteTextView myAutoComplete = (AutoCompleteTextView) searchView.findViewById(R.id.AutoCompleteTextView_declared_in_the_xml);
   // autocomplete thingie

        String[] name_mov = new String[movie_categ.size()];
        name_mov = movie_categ.toArray(name_mov);

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

        myAutoComplete.setAdapter(adapter);
        myAutoComplete.setThreshold(2);

        //