listadapter的新意图

9jyewag0  于 2021-07-13  发布在  Java
关注(0)|答案(2)|浏览(398)

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

  1. for (int i = 0; i < nlProject.getLength(); i++) {
  2. // Neue HashMap erstellen
  3. HashMap<String, String> map = new HashMap<String, String>();
  4. Element e = (Element) nlProject.item(i);
  5. // Jedes Kind-Knoten zur HashMap
  6. map.put(KEY_UUID, parser.getValue(e, KEY_UUID));
  7. map.put(KEY_NAME, parser.getValue(e, KEY_NAME));
  8. map.put(KEY_JOBTITLE, parser.getValue(e, KEY_JOBTITLE));
  9. map.put(KEY_JOBINFO, parser.getValue(e, KEY_JOBINFO));
  10. map.put(KEY_PROJECT_IMAGE, parser.getValue(e, KEY_PROJECT_IMAGE));
  11. //Hashmap zur ArrayList hinzufügen
  12. menuItems.add(map);
  13. }
  14. ListAdapter adapter = new SimpleAdapter(ListViewActivity.this, menuItems,
  15. R.layout.list_item_projects,
  16. new String[]{KEY_JOBTITLE, KEY_JOBINFO},
  17. new int[]{R.id.jobtitle, R.id.jobinfo});
  18. setListAdapter(adapter);

如果我单击一个项目,我想加载一个显示我的任务数据的新窗口
代码如下:

  1. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  2. //Neue Oberfläche starten
  3. Intent in = new Intent(ListViewActivity.this, ListMenuItemActivity.class);
  4. in.putExtra(KEY_TITLE,"title");
  5. in.putExtra(KEY_INFO,"info");
  6. in.putExtra(KEY_LOCATION, "location");
  7. startActivity(in);
  8. ListAdapter taskadapter = new SimpleAdapter(this, menuItems,
  9. R.layout.list_item_tasks,
  10. new String[]{KEY_TITLE, KEY_INFO, KEY_OBJECT, KEY_LOCATION},
  11. new int[]{R.id.title, R.id.info, R.id.object, R.id.location});
  12. setListAdapter(taskadapter);

问题是它将listadapter(适配器)更改为taskadapter,而不是创建新的活动/意图
我怎样才能解决这个问题?

dm7nw8vv

dm7nw8vv1#

您可以使用 putStringArrayList(String key, ArrayList<String> value) 方法;例如,

  1. ArrayList<String> stringArray = new ArrayList<String>();
  2. stringArray.add("The String value you want");
  3. stringArray.add("Another String value you want");

对于int数组,使用 putIntArray(String key, int[] value) 方法还可以检查这个lilink以供参考 EXTRA 领域。

cs7cruho

cs7cruho2#

正如上面的评论所回复的那样,您只需编写代码即可打开活动。

  1. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  2. //Neue Oberfläche starten
  3. Intent in = new Intent(ListViewActivity.this, ListMenuItemActivity.class);
  4. in.putExtra(KEY_TITLE,"title");
  5. in.putExtra(KEY_INFO,"info");
  6. in.putExtra(KEY_LOCATION, "location");
  7. startActivity(in);
  8. });

然后可以在新活动中设置列表适配器

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

希望对你有帮助。。。

展开查看全部

相关问题