gpt4 book ai didi

java - 如何从ArrayAdapter列表中启动新的Fragment?

转载 作者:行者123 更新时间:2023-12-02 04:44:22 24 4
gpt4 key购买 nike

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

举例说明如何使用 ArrayAdapter List 打开新 fragment

ConfigFragment.java

公共(public)类 ConfigFragment 扩展 Fragment {

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

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

这是我的几个 fragment 。

Interfaces.java、IP.java、Routes.java、Queues.java、Log.java

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

最佳答案

您通过执行事务来打开 fragment ,
读这个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


}
});

关于java - 如何从ArrayAdapter列表中启动新的Fragment?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56496016/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com