Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText with history

I want to show the history of text introduced in a TextView. It should be something similar to the search bar on google play:

google play search

By the moment I'm using an AutoCompleteTextView with android:completionThreshold="1", but I would like to don't need to write any text before suggestions starts.

Any ideas??

like image 677
Miguel Avatar asked Feb 20 '13 11:02

Miguel


1 Answers

Try this its working fine:

MainActivity.java

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.os.Build;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        final String[] COUNTRIES = new String[] {
            "Belgium", "France", "Italy", "Germany", "Spain"
        };

        // In the onCreate method
        AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, COUNTRIES);
        textView.setAdapter(adapter);
    }
}

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

<AutoCompleteTextView
    android:id="@+id/autoCompleteTextView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:text="AutoCompleteTextView" >

    <requestFocus />
</AutoCompleteTextView>

</LinearLayout>
like image 56
vijay Avatar answered Sep 25 '22 15:09

vijay