0

以下是一个位置选择器,我想向此微调器列表视图添加不同的图标。它适用于我正在尝试开发的应用程序。这样我也可以对其他微调器使用相同的方法

public class Addplace extends Activity implements OnItemSelectedListener {

    public String items;
    EditText name;
    Button add;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.addpoint);

        // Spinner element
        Spinner spinner = (Spinner) findViewById(R.id.spinner);
        name = (EditText) findViewById(R.id.nameplace);
        add = (Button) findViewById(R.id.addplace);

        // Spinner click listener
        spinner.setOnItemSelectedListener(this);

        // Spinner Drop down elements
        List<String> categories = new ArrayList<String>();
        categories.add("Outdoor");
        categories.add("Shop");
        categories.add("Professional & Other place");
        categories.add("College & University");
        categories.add("Food");
        categories.add("Travel");
        categories.add("Residences");
        categories.add("Club");
        categories.add("Bar & Pub");
        categories.add("Services");

        // Creating adapter for spinner
        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, categories);

        // Drop down layout style - list view with radio button
        dataAdapter
                .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        // attaching data adapter to spinner
        spinner.setAdapter(dataAdapter);

        add.setOnClickListener(new View.OnClickListener() {

            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                String nameplace = name.getText().toString();

                Toast.makeText(getApplicationContext(), nameplace + items,
                        Toast.LENGTH_SHORT).show();
            }
        });
    }

    public void onItemSelected(AdapterView<?> parent, View view, int position,
            long id) {
        // On selecting a spinner item
        items = parent.getItemAtPosition(position).toString();
    }

    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }

}

请善待帮助。

谢谢

4

1 回答 1

1

您将需要扩展 ArrayAdapter,并覆盖其方法并为每一行添加所需的 xml,看看这个: http: //www.coderzheaven.com/2011/07/18/customizing-a-spinner-in -安卓/

于 2012-07-09T13:45:21.680 回答