0

我正在使用微调器和自定义适配器(没有单选按钮)。微调器正在选择第一个值并传递不应发生的意图。

我的要求是当我单击微调器中的某个项目时,只会发生相应的操作。

我的代码如下。

CustomAdapter<String> adapter = new CustomAdapter<String>(this,                 android.R.layout.simple_spinner_dropdown_item,
                new String[] { "Add/Delete symbols", "forex","metal" });
        adapter.setDropDownViewResource(R.drawable.spinner_button);
chooseMarket.setPrompt("Currency settings");
        chooseMarket.setAdapter(adapter);

chooseMarket.setOnItemSelectedListener(new OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> parent,View view, int pos, long id) {

String selectedItem = chooseMarket.getSelectedItem().toString();
if (selectedItem.equalsIgnoreCase("Add/Delete symbols")) {
//Intent passing here
}

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

                    }

});

//我的自定义适配器

private static class CustomAdapter<T> extends ArrayAdapter<String> {
    public CustomAdapter(Context context, int textViewResourceId,
            String[] objects) {
        super(context, textViewResourceId, objects);
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View view = super.getView(position, convertView, parent);
        TextView textView = (TextView) view
                .findViewById(android.R.id.text1);
        // RadioButton rb = view.findViewById(R.id.)
        textView.setText("");
        return view;
    }
}

请帮忙

4

1 回答 1

0

尝试使用这个:

private static class CustomAdapter<T> extends ArrayAdapter<String> {
public CustomAdapter(Context context, int textViewResourceId,
        String[] objects) {
    super(context, textViewResourceId, objects);
}

public View getView(int position, View convertView, ViewGroup parent) {
    View view = super.getView(position, convertView, parent);
    TextView textView = (TextView) view
            .findViewById(android.R.id.text1);
    // RadioButton rb = view.findViewById(R.id.)
    textView.setText(objects[position]);

    view.setOnclickListner(new OnClickListener){

    String selectedItem = textView.getText().toString();
    if (selectedItem.equalsIgnoreCase("Add/Delete symbols")) {
       //Intent passing here
    }
    }

    return view;
}}
于 2013-08-09T10:54:17.880 回答