Now I found an interesting thing: there is a widget called AutoCompleteTextView .
You need to install an adapter that stores available automatically completed records. If you catch a text change event, you only need to get the current input from the text view and implement a search for available URLs and add the result to the array adapter. These new entries will appear as available automatically completing the current entry.
:
public class AutoCompleteTest
extends Activity
implements TextWatcher
{
private AutoCompleteTextView autoCompleteView;
@Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(layoutRes);
this.autoCompleteView = (AutoCompleteTextView) findViewById(viewId);
this.autoCompleteView.addTextChangedListener(this);
this.autoCompleteView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
public void onTextChanged(final CharSequence currentSubmission, final int start, final int before, final int count)
{
new Thread() {
@Override
public void run()
{
final String[] urls;
final Bundle data = new Bundle();
data.putStringArray("urls", urls);
final Message msg = new Message();
msg.setData(data);
MultiTouchTest.this.messageHandler.sendMessage(new Message());
}
}.start();
}
public void afterTextChanged(final Editable s)
{
}
public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after)
{
}
private final Handler messageHandler = new Handler() {
@Override
@SuppressWarnings("unchecked")
public void handleMessage(final Message msg)
{
final ArrayAdapter<String> adapter = (ArrayAdapter<String>) MultiTouchTest.this.autoCompleteView.getAdapter();
final String[] urls = msg.getData().getStringArray("urls");
for (final String url : urls)
{
adapter.add(url);
}
adapter.notifyDataSetChanged();
}
};
}
, , URL-.