0

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();  

    });
4

1 回答 1

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)

您夸大了布局,但您只是在“确定”按钮中将 AutoCompleteTextView 传递给适配器......在显示对话框之前设置 AutoCompleteTextView。

于 2013-01-20T17:51:07.453 回答