如何从ArrayAdapter列表中启动新片段?

时间:2019-06-07 14:14:31

标签: java android listview fragment adapter

我的代码有问题,我不知道该怎么做。下面我描述我的代码

给我示例如何使用ArrayAdapter List打开新片段

ConfigFragment.java

公共类ConfigFragment扩展了片段{

ListViewAdapter list;
String ConfigMenu[] = {
        "Interfaces",
        "IP Address",
        "Routes",
        "Queues",
        "Log",
        "Reboot"
};
Integer ConfigIcon[] = {
        R.drawable.ic_interface,
        R.drawable.ic_ppp,
        R.drawable.ic_routing,
        R.drawable.ic_queue,
        R.drawable.ic_log,
        R.drawable.ic_reboot
};

public ConfigFragment() {

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_config, container, false);

    ListViewAdapter adapter = new ListViewAdapter(getActivity(), ConfigIcon, ConfigMenu);
    ListView listView = (ListView) view.findViewById(R.id.listview_fragment_config);
    listView.setAdapter(adapter);

    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                String PilihMenu = ConfigMenu[+position];
                Toast.makeText(getContext(), PilihMenu, Toast.LENGTH_SHORT).show();
        }
    });

    return view;
}

我有几个片段,但是我不知道如何通过ArrayAdapter打开这些片段

这是我的几个片段。

Interfaces.java,IP.java,Routes.java,Queues.java,Log.java

我需要你的帮助。非常感谢

1 个答案:

答案 0 :(得分:0)

您通过进行交易来打开片段,
如果您是新手,请阅读此https://developer.android.com/guide/components/fragments
跳前要学习一些基本知识

  listView.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            String PilihMenu = ConfigMenu[+position];
            Toast.makeText(getContext(), PilihMenu, Toast.LENGTH_SHORT).show();

           //  You do your transaction here


    }
});