ListAdapter 的新 Intent
new Intent with ListAdapter
我有一个 ListView
从 XML-File
加载项目数据
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);
如果我点击一个项目,我想加载一个新的 window 显示我的任务数据
代码如下:
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(adapter) 更改为 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);
希望对您有所帮助...
您可以使用 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");
对于使用 putIntArray(String key, int[] value)
方法的 Int 数组,还请检查此 lilink 以获取有关 EXTRA
字段的参考。
我有一个 ListView
从 XML-File
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);
如果我点击一个项目,我想加载一个新的 window 显示我的任务数据
代码如下:
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(adapter) 更改为 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);
希望对您有所帮助...
您可以使用 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");
对于使用 putIntArray(String key, int[] value)
方法的 Int 数组,还请检查此 lilink 以获取有关 EXTRA
字段的参考。