使用来自WAMP服务器的数据填充网格视图

时间:2017-05-12 10:38:25

标签: android wampserver

我有这个XML文件,它有一个网格视图

    <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
            app:layout_scrollInterpolator="@android:anim/linear_interpolator"
            app:toolbarId="@+id/toolbar">

            <ImageView
                android:id="@+id/app_bar_image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitXY"
                android:src="@drawable/action_poster"
                android:transitionName="typeImage"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"></android.support.v7.widget.Toolbar>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">



            <RelativeLayout
                android:layout_width="368dp"
                android:layout_height="0dp"
                tools:layout_editor_absoluteY="275dp"
                tools:layout_editor_absoluteX="8dp">

                <GridView
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="80dp"
                    android:columnWidth="80dp"
                    android:gravity="center"
                    android:numColumns="auto_fit"
                    android:stretchMode="columnWidth">

                </GridView>

            </RelativeLayout>



    </android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>

这里是网格的每个项目:

class GridViewcustomadapter extends ArrayAdapter {
    Context context;


    public GridViewcustomadapter(Context context) {
        super(context, 0);
        this.context=context;
    }

    public int getCount(){
        return 24;
    }

如何使用WAMP服务器中的表格中的数据填充此网格,该服务器的表格中包含图像和标题?

1 个答案:

答案 0 :(得分:0)

首先,您需要了解如何发出HTTP请求以从本地或远程服务器获取数据。有很多令人敬畏的库,如Retrofit,Android排球,OKHTTP,这使得HTTP请求更容易。

  1. Volley
  2. Retrofit
  3. OKHTTP
  4. 如果您不理解为什么需要发出HTTP请求,它基本上是从Web服务器获取或发送数据。因此,如果您向自己的mamp服务器发出请求,您将获得该特定页面的所有if userInput[0] in batteryList: #do stuff 代码。

    对于如何使用wamp服务器中表格中的数据填充gridview 。您需要考虑制作另一个文件,该文件将返回您图像的HTML格式,例如

    JSON

    尝试不解析{ title:"Stackoverflow", image:"https://www.example.com/stackoverflow.png" } 代码因为它有点令人头疼,尽管库调用jsoup使得解析HTML更容易但仍然可以选择尝试制作服务器返回XMLJSON