İçeriğe geç

Android Otomatik Yazı Tamamlama

AutoComplateTextView ile kullanıcı birşeyler yazarken otomatik tamamlama yapmasını sağlayabiliriz.

Keys;

  • TextView
  • AutoComplateTextView
  • AutoComplateTextView TreshHold
  • AutoComplateTextView setAdapter
  • AutoComplateTextView addTestChangeListener
  • AutoComplateTextView addTestChangeListener TextWatcher
  • AutoComplateTextView addTestChangeListener TextWatcher onTextChanged
  • setText()
  • getText()
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical">
	<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textViewSelected"/>
	<AutoCompleteTextView
android:text="AutoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/autoCompleteTextView"
android:completionThreshold="3"/>
</LinearLayout>
public class MainActivity extends AppCompatActivity {

  TextView textViewSelected;
  AutoCompleteTextView autoCompleteTextView;
  String[] items = new String[] {
    "Turkey",
    "France",
    "Italy",
    "Germany",
    "Spain"
  };

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

    textViewSelected = (TextView) findViewById(R.id.textViewSelected);
    autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);

    autoCompleteTextView.setAdapter(new ArrayAdapter < String > (this, android.R.layout.simple_dropdown_item_1line, items));

    autoCompleteTextView.addTextChangedListener(new TextWatcher() {@Override
      public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

      @Override
      public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        textViewSelected.setText(autoCompleteTextView.getText());
      }

      @Override
      public void afterTextChanged(Editable editable) {

}
    });
  }
}
Tarih:Android

İlk Yorumu Siz Yapın

Bir Cevap Yazın