Autocompletetext没有出现Android Studio

时间:2018-06-03 17:26:36

标签: android android-studio autocompletetextview

我试图在android studio中制作自动完成文本。当我把编码和运行应用程序。什么都没发生!我接受了源代码,并且完全没有发生任何事情。也许我在代码中犯了一些错误,因为我是初学者。

这是我的代码

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. 如何让它运行?
  2. 如果我放置了超过1个自动填充文本,我应该如何编写代码?
  3. TQ

1 个答案:

答案 0 :(得分:0)

转到文件并点击invalidate cache / restart,这肯定会有效..