在ActionBarSherlock库中的Array Adapter上使用setOnClickListner

时间:2013-04-10 02:31:30

标签: android android-fragments actionbarsherlock android-arrayadapter

我想在ActionBarSherlock中的ArrayAdapter上添加setOnClickListner,这样当我点击该项时,它会更改片段,但顶部的操作栏会一直显示相同的栏(就像完整的布局会被更改,但操作栏除外)

如何在此代码中添加setOnClickListner。这是片段之一的代码:

    public class DetailsFragment extends SherlockListFragment{

        /** An array of items to display in ArrayList */
        String details_data[] = new String[]{
            "Personal Info",
            "Emergency Contacts",
            "Application Codes",
        };

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
            /** Creating array adapter to set data in listview */
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity().getBaseContext(), android.R.layout.simple_list_item_multiple_choice, details_data);

            /** Setting the array adapter to the listview */
            setListAdapter(adapter);

            return super.onCreateView(inflater, container, savedInstanceState);
        }

        @Override
        public void onStart() {
            super.onStart();

            /** Setting the multiselect choice mode for the listview */
            getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

        }
    }

1 个答案:

答案 0 :(得分:1)

片段可以向操作栏提供项目,但操作栏与活动相关联,而不是片段。如果删除并添加其他片段,操作栏将保持不变。