Reputation: 219
I am using Android Studio to create an app. I have XML data like this:
I want my first activity to show a list of names of employees. When I click on any name, I want my second activity to show a list of images based on the name I've clicked. How do I do that?
Upvotes: 1
Views: 516
Reputation: 164
Android's XmlPullParser will be of great use in this.
There are two key methods: next() and nextToken(). While next() provides access >to high level parsing events, nextToken() allows access to lower level tokens.
The current event state of the parser can be determined by calling the >getEventType() method. Initially, the parser is in the START_DOCUMENT state.
The method next() advances the parser to the next event. The int value returned >from next determines the current parser state and is identical to the value >returned from following calls to getEventType ().
Here is an example from the link above:
public static void main (String args[])
throws XmlPullParserException, IOException
{
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput( new StringReader ( "<foo>Hello World!</foo>" ) );
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_DOCUMENT) {
System.out.println("Start document");
} else if(eventType == XmlPullParser.START_TAG) {
System.out.println("Start tag "+xpp.getName());
} else if(eventType == XmlPullParser.END_TAG) {
System.out.println("End tag "+xpp.getName());
} else if(eventType == XmlPullParser.TEXT) {
System.out.println("Text "+xpp.getText());
}
eventType = xpp.next();
}
System.out.println("End document");
}
The question above is a bit broad, but i will try and provide some clues on how to do it:
You should iterate through your data, create a list of Employees POJOs, and use that in your ListView's adapter. You can also set an on click listener for each item and then use an imageview to display the images.
Upvotes: 1