listadapter的新意图

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

我有一个 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,而不是创建新的活动/意图
我怎样才能解决这个问题?

dm7nw8vv

dm7nw8vv1#

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

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

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

cs7cruho

cs7cruho2#

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

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

希望对你有帮助。。。

相关问题