【问题标题】:Android Spinner not reacting to any click eventAndroid Spinner 对任何点击事件都没有反应
【发布时间】:2019-09-24 22:29:06
【问题描述】:

我构建了一个自定义的Spinner,它有一个加载一些数据的方法,一旦加载了这些数据(在ArrayList 事件中),它们就会显示出来。

除了一些烦人的东西外,一切正常:我检测到此微调器上的任何点击事件(以更改所选项目),我的 OnItemSelectedListener 仅在开始时触发一次...

但比blabla更好,这里是代码:

public class ActionChooser extends Spinner {
    private Context c;
    ArrayList<Event> events;
    OnItemSelectedListener listener;

    public ActionChooser(Context context) {
        super(context);
        this.c = context;
        init();
    }

    public ActionChooser(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.c = context;
        init();
    }


    private void init() {
        // events arrayList is filled by a XML parser there, too long and uninteresting for SO
        setAdapter(new CustomAdapter());
        OnItemSelectedListener l = new OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                Log.d("ActionChooser", "i:" + i);
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
                Log.d("ActionChooser", "nothing");
            }
        };
        setOnItemSelectedListener(l);
    }


    private class Event {

        String methodSignature;
        String name;
        boolean isBefore;
        ArrayList<Param> data;
    }

    private class Param {
        int pos;
        String name;
    }

    private class CustomAdapter extends BaseAdapter implements SpinnerAdapter {


        @Override
        public int getCount() {
            return events.size();
        }

        @Override
        public Object getItem(int i) {
            return events.get(i);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            View row = inflate(c, R.layout.row_action_chooser, null);
            TextView tv = (TextView) row.findViewById(R.id.title);
            TextView methodName = (TextView) row.findViewById(R.id.javaM);
            CheckBox cb = (CheckBox) row.findViewById(R.id.checkbox);
            LinearLayout ll = (LinearLayout) row.findViewById(R.id.dataContainer);
            tv.setText(WordUtils.capitalize(events.get(i).name));
            methodName.setText(events.get(i).methodSignature);
            cb.setChecked(events.get(i).isBefore);
            for (Param p : events.get(i).data) {
                TextView pt = (TextView) row.findViewById(R.id.parameterTitle);
                pt.setVisibility(VISIBLE);
                TextView ptv = new TextView(c);
                ptv.setText(p.name + " (pos: " + p.pos + ")");
                ptv.setTextSize(10);
                ll.addView(ptv);
            }
            return row;
        }
    }
}

微调器看起来或多或少不错:

但我不能点击它(实际上我可以但它什么也没做,它甚至不会使弹出窗口消失......)。

有人有想法吗?

【问题讨论】:

    标签: android android-layout android-spinner


    【解决方案1】:

    我明白了!

    伙计们,永远不要将任何 Checkbox 放在 Spinner 的子视图中。这就是问题所在,如果您删除 Checkbox 它就可以正常工作!

    【讨论】:

    • 嗯,为什么不是,但实际上我只是将Android问题删除并报告它;)
    猜你喜欢
    • 2013-01-08
    • 2019-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-05
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    相关资源
    最近更新 更多