Reputation:
I have a ListView
loading project data from an 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);
if I click on an item I want to load a new window displaying my task-data
Here is the code:
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);
The problem is that it change the ListAdapter(adapter) to taskadapter instead of creating a new activity/intent
How can i solve this problem?
Upvotes: 0
Views: 74
Reputation: 1139
You can add a String array as an extra by using putStringArrayList(String key, ArrayList<String> value)
method; for example,
ArrayList<String> stringArray = new ArrayList<String>();
stringArray.add("The String value you want");
stringArray.add("Another String value you want");
And for the Int array by using putIntArray(String key, int[] value)
method also check this lilink for reference about EXTRA
fields.
Upvotes: 0
Reputation:
As replied in the comments above you have to write only the code to open the 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);
});
You can then set the list adapter in new 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);
Hope it helps...
Upvotes: 1