【发布时间】:2014-04-05 06:17:28
【问题描述】:
当我输入内容时,我会得到一个自动完成预测。就像当我输入“Joh”时,我得到“John F. Kennedy”。现在,如果用户点击“John F. Kennedy”,它会将他带入一个活动,该活动向他提供有关 John F. Kennedy 的信息。我应该怎么做才能得到这个?如何使自动完成预测可点击?
package com.mavenmaverick.autocomplete_test;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class MainActivity extends Activity {
String[] presidents= { "John F. Kennedy",
"Lyndon B. Johnson",
"Richard Nixon",
"Gerald Ford",
"Jimmy Carter",
"Ronald Reagan",
"George H. W. Bush",
"Bill Clinton",
"George W. Bush",
"Barack Obama"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.select_dialog_item, presidents);
textView.setThreshold(3);
textView.setAdapter(adapter);
}
}
【问题讨论】:
标签: java android autocomplete clickable