如何使用来自 json 的 viewflipper 为图像和文本制作幻灯片

How to make slideshow for images and text using viewflipper from json

//mainactivity.xml

<ViewFlipper 
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<RelativeLayout
    android:id="@+id/relativeLayout2"
    android:layout_width="match_parent"
    android:layout_height="279dp"
    android:layout_marginBottom="5dp"
    android:layout_marginTop="5dp"
    android:background="@android:color/background_light"
    android:gravity="center" >

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/imageView7"
        android:layout_marginLeft="14dp"
        android:layout_marginTop="14dp"
        android:text="Event Name" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView3"
        android:layout_below="@+id/textView3"
        android:text="Venue, Date"
        android:textSize="12sp" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView4"
        android:layout_below="@+id/textView4"
        android:text="Description"
        android:textSize="12sp" />

    <ImageView
        android:id="@+id/imageView7"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView2"
        android:layout_marginTop="14dp"
        android:src="@drawable/demo" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp"
        android:text="Event of the Week" />

</RelativeLayout>
</ViewFlipper>

我想为上述布局实现图像和文本的幻灯片放映。这些值来自我的服务器,使用 json。我该如何实施。我被困在这里。有没有人知道答案。

任何人都有参考link..

这是您要遵循的基本流程。

1.下载 JSON 数据:您需要使用后台线程和 HTTP 客户端来执行此操作。也许AsyncTaskand DefaultHttpClient

2。解析 JSON 数据: 下载 JSON 后,您需要创建 JSONObjects 并将它们解析为数据模型 classes 以存储数据.您的模型 class 可能看起来像这样:

public class SlideshowImage {
    public String text;
    public String imageUrl;
} 

理想情况下,您最终会得到来自 JSON 的 List 个 SlideshowImages。

3。如果需要,存储数据(可选): 如果你想将这些模型 classes 存储在数据库中,也可以这样做。但是,如果您打算每次都实时加载此信息,则可能不需要。

4 使用 'SlideshowImages' 的列表填充您的视图: 最后您可以访问 SlideshowImage classes 将数据加载到您的每个视图中文本视图和图像视图。

SlideshowImage model = slideshowImageList.get(0);
textView1.setText(model.text);

您还需要下载 imageUrls 以获取 Bitmaps,以便您可以设置 ImageView。您应该参考 this 问题寻求帮助。