Skip to content

Instantly share code, notes, and snippets.

@jesselima
Created May 14, 2018 18:12
Show Gist options
  • Save jesselima/47b0de7d0724ac70309caec9988974e7 to your computer and use it in GitHub Desktop.
Save jesselima/47b0de7d0724ac70309caec9988974e7 to your computer and use it in GitHub Desktop.
Simple auto-complete input text.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<AutoCompleteTextView
android:id="@+id/countries_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.constraint.ConstraintLayout>
package com.android.myapplication;
import android.content.res.Resources;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import java.util.Locale;
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_main);
String locale = Resources.getSystem().getConfiguration().locale.getLanguage();
Log.v("Language: ", locale);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, EVENTS);
AutoCompleteTextView textView = findViewById(R.id.countries_list);
textView.setAdapter(adapter);
}
private static final String[] EVENTS = new String[] {
"Salto em Altura", "Salto com Vara", "Salto em Distância", "Salto Triplo", "100m", "200m", "400m", "10000m", "110m com barreiras"
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment