关闭对话框

时间:2017-08-04 10:39:07

标签: java android spinner

我在列表vivew上面有一个微调器。 我从微调器中选择项目,列表视图已更新,我的应用程序正常工作。 但是当从listView(带描述和广告)中选择一个图层时,打开一个对话框 当我点击广告对话框时,关闭对话框 但没有使用OnItemSelectedListenet 通过返回上一页并重新进入页面,微调器工作

OnItemSelectedListener selectedListener1 = new OnItemSelectedListener() {

    @Override
    public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
      //my code     
    }

    @Override
        public void onNothingSelected(AdapterView<?> adapterView) {}
    };

    OnItemSelectedListener selectedListener2 = new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int arg2, long arg3) {
            //my code
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    };

    ArrayAdapter<String> adapterSpinner1 = new AdapterSpinner(G.context, R.layout.spinner_item, items1);
    sp1.setAdapter(adapterSpinner1);
    sp1.setOnItemSelectedListener(selectedListener1);

    ArrayAdapter<String> adapterSpinner2 = new AdapterSpinner(G.context, R.layout.spinner_item, items2);
    sp2.setAdapter(adapterSpinner2);
    sp2.post(new Runnable() {
        @Override
        public void run() {
            sp2.setSelection(3);
        }
    });
    sp2.setOnItemSelectedListener(selectedListener2);
}

1 个答案:

答案 0 :(得分:0)

而不是创建不同的选定侦听器,使用onItemSelectedListener实现活动它将为您提供方法

@Override
    public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
if(view==sp1){//do something}
    }

    @Override
    public void onNothingSelected(AdapterView<?> adapterView) {

    }

并在你的oncreate

sp1.setOnItemSelectedListener(this);
sp2.setOnItemSelectedListener(this);