如何使用setOnItemClickListener从片段移动到另一个片段

时间:2019-06-22 13:54:44

标签: android android-fragments fragment

如何使用setOnItemClickListener从片段移动到另一个片段?

public class dashboardFragment extends Fragment {
    ListView lv;

    SearchView searchView;
    ArrayAdapter<String> adapter;
    String[] menuItem ={"a","b","c","d"};
    private ArrayList<String> data;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        View view = inflater.inflate(R.layout.fragment_dashboard, container, false);
        lv = (ListView) view.findViewById(R.id.list_item);
        adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,menuItem);
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
             //what the code
            }
        });

        return view;

    }
}

0 个答案:

没有答案