在ListView标题中的微调器时未调用微调器setOnItemSelectedListener

时间:2013-03-18 19:55:28

标签: android android-listview spinner

如果我将微调器放在我的ListView主文件中,setOnItemSelectedListener就像正常一样被调用。

就像标题所说,如果我将微调器放入我的ListView 标题,则不是。这是配置:

        ListView listView = getListView();
        listView.setDivider(null);

        LayoutInflater inflater = getActivity().getLayoutInflater();
        ViewGroup header = (ViewGroup) inflater.inflate(
                R.layout.mastercat_header, listView, false);

        listView.addHeaderView(header, null, false);

        sort = (Spinner) getActivity().findViewById(R.id.spinner1);
        strings = getActivity().getResources().getStringArray(
                R.array.sorting_cats);
        sAdapter = new SpinnerSortAdapter(getActivity(),
                android.R.layout.simple_spinner_item, strings);
        sAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sort.setAdapter(sAdapter);
        sort.setOnItemSelectedListener(new MyOnItemSelectedListener()); // Not working properly. 




 public class MyOnItemSelectedListener implements OnItemSelectedListener {

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

    if (pos == 0) {

        //stuff
    }

    if (pos == 1) {
        // stuff
    }

}

public void onNothingSelected(AdapterView<?> parent) {
    // Do nothing.
}

}

其他信息:此列表视图是jfeinstien的SlidingMenu库中滑块菜单的一部分。它也是Fragment

我发现了错误或我的代码错了吗?

0 个答案:

没有答案