是否有可能有微调,并在同一页上的列表视图? [英] Is it possible to have a spinner and a list view on the same page?
本文介绍了是否有可能有微调,并在同一页上的列表视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想有一个微调在页面的顶部,然后按一下用户已经从微调选择产生微调下方的列表视图中,没有人知道一个很好的教程,这还是有一定的code躺在附近可能帮助?
I want to have a spinner at the top of page, and then generate a list view below the spinner according to what the user has selected from the spinner, does anyone know a good tutorial for this or have some code lying around that might help?
推荐答案
使用ArrayAdapter在一个字符串数组填充微调一个简单的例子:
A simple example using an ArrayAdapter over a string array for populating the spinner:
// Create string array adapter to populate spinner
ArrayAdapter<CharSequence> adapter =
ArrayAdapter.createFromResource(this, R.array.spinner_string_array,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Set the spinners content adapter and add onSelect listener
Spinner spinnerExample = (Spinner)findViewById(R.id.id_to_spinner);
spinnerExample.setAdapter(adapter);
spinnerExample.setOnItemSelectedListener(listerner);
// Get a reference to the ListView that will be used in the listener
listViewToPopulate = (ListView)findViewById(R.id.id_to_listview);
和相关OnClickListener处理列表人口:
And the associated OnClickListener to handle list population:
OnItemSelectedListener listerner = new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> paramAdapterView,
View paramView, int paramInt, long paramLong) {
String selection = (String)paramAdapterView.getItemAtPosition(paramInt);
// Populate list based on selection
}
@Override
public void onNothingSelected(AdapterView<?> paramAdapterView) {
// do nothing
}
};
这篇关于是否有可能有微调,并在同一页上的列表视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文