是否有可能有微调,并在同一页上的列表视图?有可能、并在、视图、列表

2023-09-04 05:31:44 作者:南风入我怀

我想有一个微调在页面的顶部,然后按一下用户已经从微调选择产生微调下方的列表视图中,没有人知道一个很好的教程,这还是有一定的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
    }
};