1

如果我将微调器放在我的ListView主文件中,setOnItemSelectedListener则正常调用。

就像标题说的那样,如果我把微调器放到我的ListView header中,它不是。这是配置:

        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.
}

}

附加信息:此列表视图是 jfeinstienSlidingMenu库中滑块菜单的一部分。它也是一个Fragment.

我发现错误还是我的代码错误?

4

0 回答 0