自动完成文本框不会显示建议

时间:2013-01-20 17:45:09

标签: android android-layout

logcat没有错误,但建议列表不显示我不知道我哪里出错了。我在警告对话框中膨胀了自动完成视图。这是我的代码

reg_btn.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {


                final String[] devplatforms =
                     {
                     "C",
                     "C++",
                     "Java",
                     "iPhone",
                     "Android",
                     "ASP.NET",
                     "PHP",
                     "Python",
                     };


                AlertDialog.Builder adb = new AlertDialog.Builder(SettingsMain.this);
                LayoutInflater inflater = SettingsMain.this.getLayoutInflater(); 
                final View searchlayout = inflater.inflate(R.layout.search_friend, null);

               adb.setView(searchlayout)

               .setPositiveButton("Ok", new DialogInterface.OnClickListener() {  
                    public void onClick(DialogInterface dialog, int whichButton) {  
                        AutoCompleteTextView friend_name;
                        friend_name = (AutoCompleteTextView) searchlayout.findViewById(R.id.friend_name);
                        friend_name.setThreshold(1);
                        friend_name.setAdapter(new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_dropdown_item_1line,devplatforms));

                        String name = friend_name.getText().toString();
                        Log.d( "ECHO" , "Pin Value : " + name);
                        return;                  
                       }  
                  })
               .setNegativeButton("Done", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {


                        dialog.cancel(); 
                    }
                }); 

                    adb.show();  

    });

1 个答案:

答案 0 :(得分:2)

看起来这段代码位置错误:

AutoCompleteTextView friend_name;
friend_name = (AutoCompleteTextView) searchlayout.findViewById(R.id.friend_name);
friend_name.setThreshold(1);
friend_name.setAdapter(new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_dropdown_item_1line,devplatforms));

将其移到此行上方:

adb.setView(searchlayout)

你夸大了布局,但是你只是在“Ok”按钮中传递AutoCompleteTextView适配器...在显示对话框之前设置AutoCompleteTextView