New to android, I want to render all the book results in my fragment below. But only first book is appearing. Not sure how to have all books in same picture and details format in a sequence?
XML file:
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ScrollView01" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" android:scrollbars="none" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff" android:orientation="vertical" tools:context="com.androidatc.customviewindrawer.SearchBookFrag" android:weightSum="1"> <TextView android:id="@+id/enter_keyword" android:layout_width="190dp" android:layout_height="40dp" android:textIsSelectable="true" android:layout_marginTop="33dp" android:layout_gravity="center" android:text="Enter Keyword" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_marginLeft="30dp" android:layout_centerHorizontal="true" /> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/book_keyword" android:text="" android:layout_alignRight="@+id/book_title" android:layout_alignEnd="@+id/book_title" android:layout_alignTop="@+id/enter_keyword" android:layout_toEndOf="@+id/imageView" android:layout_toRightOf="@+id/imageView" /> <Button android:id="@+id/search_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:text="@string/search" android:layout_marginTop="90dp" android:layout_gravity="center_horizontal" /> <ImageView android:layout_width="144dp" android:layout_height="190dp" android:id="@+id/imageView" android:layout_gravity="left" android:layout_marginTop="150dp" android:layout_marginLeft="10dp" android:src="@android:color/black" /> <TextView android:id="@+id/book_title" android:layout_width="190dp" android:layout_height="40dp" android:textIsSelectable="true" android:layout_marginTop="150dp" android:layout_alignParentRight="true" android:layout_gravity="right" android:text="Title" /> <TextView android:id="@+id/book_publisher" android:layout_width="190dp" android:layout_height="40dp" android:textIsSelectable="true" android:layout_alignParentRight="true" android:layout_below="@id/book_title" android:layout_weight="0.05" android:layout_gravity="right" android:text="Publisher" /> <TextView android:id="@+id/book_creator" android:layout_width="190dp" android:layout_height="40dp" android:textIsSelectable="true" android:layout_alignParentRight="true" android:layout_below="@id/book_publisher" android:layout_gravity="right" android:text="Creator" /> <TextView android:id="@+id/book_availability" android:layout_width="190dp" android:layout_height="40dp" android:textIsSelectable="true" android:layout_alignParentRight="true" android:layout_below="@id/book_creator" android:layout_weight="0.03" android:layout_gravity="right" android:text="Availablity" /> </RelativeLayout> </LinearLayout> </ScrollView> Part of java class - where I am parsing xml results is as below, not sure how to retrieve all results?
public void readDetails(String response) { DocumentBuilder builder = null; try { builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputSource src = new InputSource(); src.setCharacterStream(new StringReader(response)); // Toast.makeText(getActivity().getApplicationContext(), "src:" + "\n" // + src, Toast.LENGTH_LONG).show(); Document doc = builder.parse(src); NodeList nodes1 = doc.getElementsByTagName("dc:title"); Toast.makeText(getActivity().getApplicationContext(), "Total Number of Books Found:" + nodes1.getLength(), Toast.LENGTH_LONG).show(); //String available = doc.getElementsByTagName("zs:numberOfRecords").item(0).getTextContent(); String title = doc.getElementsByTagName("dc:title").item(0).getTextContent(); String creator1 = doc.getElementsByTagName("dc:creator").item(0).getTextContent(); String creator2 = doc.getElementsByTagName("dc:creator").item(1).getTextContent(); String publisher = doc.getElementsByTagName("dc:publisher").item(0).getTextContent(); String description = doc.getElementsByTagName("dc:description").item(0).getTextContent(); NodeList list = doc.getElementsByTagName("dc:duedate"); src.setCharacterStream(new StringReader(response)); NodeList nodes = doc.getElementsByTagName("dc:duedate"); int cnt=0; for (int i = 0; i < nodes.getLength(); i++) { if(nodes.item(i).getTextContent().trim().isEmpty()){ cnt++; } } Log.e("TAGLOG", "" + cnt); TitleTxt.setText("Title: " + title); PublisherTxt.setText("Publisher: " + publisher); CreatorTxt.setText("Creator: " + creator1 + "," + creator2); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e){ e.printStackTrace(); Toast.makeText(getActivity().getApplicationContext(), "No Book Found", Toast.LENGTH_LONG).show(); } finally { } Here XML may return any number of results (0 to many). Any suggestions are welcome. Thanks in advance.
No comments:
Post a Comment