Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用滚动条在片段中显示xml显示的所有结果_Android_Xml_Android Fragments - Fatal编程技术网

Android 使用滚动条在片段中显示xml显示的所有结果

Android 使用滚动条在片段中显示xml显示的所有结果,android,xml,android-fragments,Android,Xml,Android Fragments,android新手,我想在下面的片段中呈现所有书籍结果。但只有第一本书出现了。不知道如何让所有的书以相同的图片和细节格式排列 XML文件: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ScrollView01" android:layout_width=

android新手,我想在下面的片段中呈现所有书籍结果。但只有第一本书出现了。不知道如何让所有的书以相同的图片和细节格式排列

XML文件:

<?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>

java类的一部分-我解析xml结果的地方如下,不确定如何检索所有结果

 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 {

    }
public void readDetails(字符串响应){
DocumentBuilder=null;
试一试{
builder=DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputSource src=新的InputSource();
src.setCharacterStream(新StringReader(响应));
//Toast.makeText(getActivity().getApplicationContext(),“src:”+“\n”
//+src,Toast.LENGTH_LONG).show();
文档doc=builder.parse(src);
NodeList nodes1=doc.getElementsByTagName(“dc:title”);
Toast.makeText(getActivity().getApplicationContext(),“找到的图书总数:”
+nodes1.getLength(),Toast.LENGTH_LONG).show();
//字符串available=doc.getElementsByTagName(“zs:numberOfRecords”).item(0.getTextContent();
字符串title=doc.getElementsByTagName(“dc:title”).item(0.getTextContent();
字符串creator1=doc.getElementsByTagName(“dc:creator”).item(0.getTextContent();
String creator2=doc.getElementsByTagName(“dc:creator”).item(1.getTextContent();
字符串publisher=doc.getElementsByTagName(“dc:publisher”).item(0.getTextContent();
String description=doc.getElementsByTagName(“dc:description”).item(0.getTextContent();
节点列表=doc.getElementsByTagName(“dc:duedate”);
src.setCharacterStream(新StringReader(响应));
NodeList nodes=doc.getElementsByTagName(“dc:duedate”);
int-cnt=0;
对于(int i=0;i

在此,XML可以返回任意数量的结果(0到多个)。欢迎提供任何建议。请提前感谢。

尝试放置id=“@+id/container”的滚动视图。因此,请删除相对布局并将其替换为滚动视图。

我希望多个结果显示在不同的行中。第一本书的显示工作正常。我不知道如何向更多的书显示第二本书(这是xml解析的结果)在滚动条的同一个片段中。上面的代码运行良好,只是我想显示所有结果。我找到了本教程,希望这是您正在寻找的,跳到10:32查看他所做的:好的,让我查看recyclerview..不知道如何做。非常感谢。