如何从SQL显示AutocompleteTextView建议?

时间:2016-10-11 07:08:29

标签: android sql autocompletetextview

下面是我的addTextChangedListener,我想从SQL中显示建议。我调试我的代码,我看到当我在autocompleteTextView中写任何字符时,然后在nMAcDetailID和cMachineName中输入值。现在我想显示建议清单。我怎样才能做到这一点?

txtMachineName.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {}

            private Timer timer=new Timer();
            private final long DELAY = 300; // milliseconds
            @Override
            public void afterTextChanged(Editable s) {
                timer.cancel();
                timer = new Timer();
                timer.schedule(
                        new TimerTask() {
                            @Override
                            public void run() {
                                // TODO: do what you need here (refresh list)
                                // you will probably need to use runOnUiThread(Runnable action) for some specific actions
                                try {
                                    Connection con = connectionClass.CONN();
                                    if (con == null) {

                                        getActivity().getParent().runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                Toast.makeText(getActivity(), "please Check Your Internet Connection", Toast.LENGTH_LONG).show();
                                            }
                                        });
                                    } else {
                                        @SuppressWarnings("WrongThread") String query = "exec App_ac_MacName "+nClintID+",'"+txtMachineName.getText()+"'";
                                        ResultSet rs = dbHelp.executeRS(query);
                                        try {
                                            while (rs.next()) {
                                                String nMAcDetailID = rs.getString("nMAcDetailID");
                                                String cMachineName = rs.getString("cMachineName");
                                            }
                                        } catch (SQLException e) {
                                            e.printStackTrace();
                                        }
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        },
                        DELAY
                );
            }
        });

0 个答案:

没有答案