<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context="com.example.mar_2300_autocompletetextview.MainActivity"
tools:ignore="MergeRootFrame" >
<AutoCompleteTextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/atv"/>
<TextView android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources> <string name="app_name">Mar_2300_AutoCompleteTextView</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string> <string-array name="test">
<item>Mercury</item>
<item>Mercury2</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
<item>Jupiter</item>
<item>Saturn</item>
<item>Uranus</item>
<item>Neptune</item>
</string-array> </resources>
package com.example.mar_2300_autocompletetextview; import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.app.Activity;
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.widget.TextView;
import android.os.Build; public class MainActivity extends Activity implements TextWatcher {
private AutoCompleteTextView atv;
private TextView tv;
private ArrayAdapter<CharSequence> adapter; @Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub } @Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub } @Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
tv.setText(atv.getText());
} @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
atv = (AutoCompleteTextView) findViewById(R.id.atv);
tv = (TextView) findViewById(R.id.textView1);
adapter = ArrayAdapter.createFromResource(this, R.array.test,
android.R.layout.simple_dropdown_item_1line);
atv.setAdapter(adapter);
atv.addTextChangedListener(this);
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }