gpt4 book ai didi

java - 使用 ListAdapter 的新 Intent

转载 作者:行者123 更新时间:2023-12-01 11:36:34 25 4
gpt4 key购买 nike

我有一个 ListView 从 XML 文件加载项目数据

for (int i = 0; i < nlProject.getLength(); i++) {

// Neue HashMap erstellen
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nlProject.item(i);

// Jedes Kind-Knoten zur HashMap
map.put(KEY_UUID, parser.getValue(e, KEY_UUID));
map.put(KEY_NAME, parser.getValue(e, KEY_NAME));
map.put(KEY_JOBTITLE, parser.getValue(e, KEY_JOBTITLE));
map.put(KEY_JOBINFO, parser.getValue(e, KEY_JOBINFO));
map.put(KEY_PROJECT_IMAGE, parser.getValue(e, KEY_PROJECT_IMAGE));


//Hashmap zur ArrayList hinzufügen
menuItems.add(map);
}

ListAdapter adapter = new SimpleAdapter(ListViewActivity.this, menuItems,
R.layout.list_item_projects,
new String[]{KEY_JOBTITLE, KEY_JOBINFO},
new int[]{R.id.jobtitle, R.id.jobinfo});

setListAdapter(adapter);

如果我点击一个项目,我想加载一个显示我的任务数据的新窗口

这是代码:

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


//Neue Oberfläche starten
Intent in = new Intent(ListViewActivity.this, ListMenuItemActivity.class);
in.putExtra(KEY_TITLE,"title");
in.putExtra(KEY_INFO,"info");
in.putExtra(KEY_LOCATION, "location");
startActivity(in);


ListAdapter taskadapter = new SimpleAdapter(this, menuItems,
R.layout.list_item_tasks,
new String[]{KEY_TITLE, KEY_INFO, KEY_OBJECT, KEY_LOCATION},
new int[]{R.id.title, R.id.info, R.id.object, R.id.location});

setListAdapter(taskadapter);

问题在于它将ListAdapter(适配器)更改为taskadapter而不是创建新的 Activity/Intent

如何解决这个问题?

最佳答案

正如上面评论中的回复,您只需编写代码即可打开 Activity 。

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


//Neue Oberfläche starten
Intent in = new Intent(ListViewActivity.this, ListMenuItemActivity.class);
in.putExtra(KEY_TITLE,"title");
in.putExtra(KEY_INFO,"info");
in.putExtra(KEY_LOCATION, "location");
startActivity(in);
});

然后您可以在新 Activity 中设置列表适配器

ListAdapter taskadapter = new SimpleAdapter(this, menuItems,
R.layout.list_item_tasks,
new String[]{KEY_TITLE, KEY_INFO, KEY_OBJECT, KEY_LOCATION},
new int[]{R.id.title, R.id.info, R.id.object, R.id.location});

setListAdapter(taskadapter);

希望对你有帮助...

关于java - 使用 ListAdapter 的新 Intent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29919825/

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