我試圖實現以下代碼片段。當然,我做了所有必要的更改以避免語法和其他錯誤。片段上沒有建議的AutoCompleteTextView
public class MainActivity extends ActionBarActivity {
private AutoCompleteTextView autoCompleteTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
autoCompleteTextView = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView);
String[]dataStorage = {"Nigeria", "Ghana", "Mali", "South Africa", "Cameroon", "Niger", "Algeria", "Zimbabwe"};
ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(), android.R.layout.select_dialog_item, dataStorage);
autoCompleteTextView.setThreshold(2);
autoCompleteTextView.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
它運行時沒有任何錯誤,但我在第一個字符後沒有得到搜索建議。首先在全屏模式下用稱爲提交的按鈕打開屏幕鍵盤。我無法得到任何建議,也許我不能看到它,因爲這個全屏鍵盤。
這行到XML,但沒有任何改變。 – appkovacs
當您鍵入某些字符以及整個activity_main.xml時,您可以發佈您的應用的屏幕截圖嗎? – weibeld
它在'TableRow'中,如下所示。應用程序屏幕看起來很簡單 ' AutoCompleteTextView> ' –
appkovacs