Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use with remote data? #143

Open
jagatappv opened this issue Jul 1, 2015 · 2 comments
Open

how to use with remote data? #143

jagatappv opened this issue Jul 1, 2015 · 2 comments

Comments

@jagatappv
Copy link

Can someone guide me how can I use auto complete with remote data?

@jensneuse
Copy link

You'll need to build you own Adapter similar to this one:
https://github.com/jnsone11/android-play-places/blob/master/PlaceComplete/Application/src/main/java/com/example/google/playservices/placecomplete/PlaceAutocompleteAdapter.java

tldr:
Instead of attaching an ArrayAdapter you'll create you own Adapter, pass your searchTerm to it (performFiltering), fetch remote data and pass it back to your AutoCompleteTextView.

I suggest to implement a Handler that posts to the adapter with a delay of 450ms and is capable of obtaining all previously sent messages. This will prevent multiple filterings when the user is typing.

Looks somewhat like this:

private static final int MESSAGE_TEXT_CHANGED = 1337;
private static final int DEFAULT_AUTOCOMPLETE_DELAY = 750;

private int mAutoCompleteDelay = DEFAULT_AUTOCOMPLETE_DELAY;

private final Handler mHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {

        PlacesAutocompleteTextview.super.performFiltering((CharSequence) msg.obj, msg.arg1);
    }
};

@Override
protected void performFiltering(CharSequence text, int keyCode) {
            mHandler.removeMessages(MESSAGE_TEXT_CHANGED);
            mHandler.sendMessageDelayed(mHandler.obtainMessage(MESSAGE_TEXT_CHANGED, 
}

@sopharasum
Copy link

You'll need to build you own Adapter similar to this one:
https://github.com/jnsone11/android-play-places/blob/master/PlaceComplete/Application/src/main/java/com/example/google/playservices/placecomplete/PlaceAutocompleteAdapter.java

tldr:
Instead of attaching an ArrayAdapter you'll create you own Adapter, pass your searchTerm to it (performFiltering), fetch remote data and pass it back to your AutoCompleteTextView.

I suggest to implement a Handler that posts to the adapter with a delay of 450ms and is capable of obtaining all previously sent messages. This will prevent multiple filterings when the user is typing.

Looks somewhat like this:

private static final int MESSAGE_TEXT_CHANGED = 1337;
private static final int DEFAULT_AUTOCOMPLETE_DELAY = 750;

private int mAutoCompleteDelay = DEFAULT_AUTOCOMPLETE_DELAY;

private final Handler mHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {

        PlacesAutocompleteTextview.super.performFiltering((CharSequence) msg.obj, msg.arg1);
    }
};

@Override
protected void performFiltering(CharSequence text, int keyCode) {
            mHandler.removeMessages(MESSAGE_TEXT_CHANGED);
            mHandler.sendMessageDelayed(mHandler.obtainMessage(MESSAGE_TEXT_CHANGED, 
}

Can you please share the full source code for this implement class ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants