-1

Im trying to make a autocompletetext in android studio. When i put the coding and run the apps.Nothing happen! i take the source and make exactly like that still nothing happen.Maybe i do a some mistake in my code, because i'm beginner.

here is my code

package my.wedee.com.taskactivity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends AppCompatActivity {


AutoCompleteTextView Airport;

String[] airport = {"India", "China", "Australia", "New Zealand", "England", "Pakistan"};

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

    //initiate an auto complete text view
    Airport = (AutoCompleteTextView) findViewById(R.id.task_airport_list);
    ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, airport);

    Airport.setAdapter(adapter);
    Airport.setThreshold(1);//start searching from 1 character
    Airport.setAdapter(adapter);   //set the adapter for displaying country name list




    }


}
  1. How do i make this running?
  2. If i put more than 1 autocomplete text, how should i put the coding?

TQ

  • If task_airport_list is too short you can't see the list. Try it with android:layout_width="match_parent". Why do you call Airport.setAdapter(adapter) twice? –  Jun 03 '18 at 17:43
  • i already put "match_parent".i call the setAdapter twice because i just copying the code from the toturial. – Nurudin Mohd Shah Jun 03 '18 at 20:18

1 Answers1

0

go to file and hit invalidate cache/restart , surely this will work ..