从网络填充 BaseAdapter

发布于 2024-10-05 10:06:44 字数 290 浏览 0 评论 0原文

我有一个像这样的 JSON 数组: [{"usename":"user", "user_pic":"图片", "photo":"http://hfhfhfhhfh.jpg", "timestamp":"10-09-10"} {"username":"用户2”,..........}]
我在这个数组中有 10 个 JSONObject,我想用它来填充流:
头像 - 昵称
照片
时间戳
是我的应用程序的流,我想要其他用户的最新帖子。
我怎样才能填充流? 我想我可以使用基础适配器是正确的吗?

太感谢了!

I've a JSON array like this:
[{"usename":"user", "user_pic":"picture", "photo":"http://hfhfhfhhfh.jpg", "timestamp":"10-09-10"} {"username":"user2", ..........}]
I've 10 JSONObject in this array, and I want use it for populate a stream with:
Avatar - Nickname
Photo
Timestamp
Is a stream of my application, I want have the latest post of other user.
How can I populate the stream?
I think i could use a baseadapter is correct?

Thank you so much!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

段念尘 2024-10-12 10:06:44

是的,您需要 BaseAdapter 或 ArrayAdapter,具体取决于您的实现。
但是您必须覆盖默认实现才能按照您希望的方式显示列表项。
您还可以在此处查看列表视图示例。
http://developer.android .com/resources/samples/ApiDemos/src/com/example/android/apis/view/index.html

基本上你在你的情况下可能想要的是。

  1. 在开始下载 json 之前有一个进度对话框或其他一些指示器。
  2. 下载 json.
  3. 解析它并将其转换为对象列表[可能是 Arraylist]
  4. 将此列表传递到您的 ListView 适配器。这是您的主要问题,您需要覆盖 BaseAdapter 以创建您自己的适配器。
    这是谷歌搜索的一个例子
    http://developerlife.com/tutorials/?p=327
    如果您需要更多帮助,您可能需要搜索更多示例。
  5. 将列表传递给适配器后,您将需要关闭进度对话框。

Yes you need a BaseAdapter or an ArrayAdapter depending on your implementation.
But you would have to overwritye the default implementation to show your list items as you want them to be displayed.
You may also check the listview examples here.
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/index.html.

Basically what you might want in your situation is.

  1. Have a progress dialog or some other indicator just before you start downloading json.
  2. Download json.
  3. parse it and Convert it into your list of objects[probably Arraylist]
  4. Pass this list on to your ListView Adapter. This was your main issue and you need to overwrite the BaseAdapter to create your own adapter.
    Here is an example from google search
    http://developerlife.com/tutorials/?p=327.
    You may need to search for more example if you need more help.
  5. Once you pass the list to your adapter you will need to close the progress dialog.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文