小编Rob*_*Ray的帖子

Json DateTime在Android中解析

我的API给出了这个结果:

{
    "Posts": [{
        "UseName": "Robert Ray",
        "DateTime": "\/Date(1376841597000)\/",
        "PostText": "Welcome!!\u003cbr\u003eThis Is my Text"
    }]
}
Run Code Online (Sandbox Code Playgroud)

我像这样解析我的JSON

try {
    Posts = json.getJSONArray(TAG_POSTS);

    for(int i = 0; i < Posts.length(); i++){
        JSONObject c = Posts.getJSONObject(i);
        String post_text = c.getString("PostText"); 

        String strDate = "2013-05-15T10:00:00-0700";
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
        Date date = (Date) dateFormat.parse(c.getString("DateTime"));
    }
} catch (JSONException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
} catch (ParseException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
} 
Run Code Online (Sandbox Code Playgroud)

但它不工作,我想要的是它应该计算自用户发布帖子以来经过的时间,
即我们必须用JSON中的日期减去当前数据,然后在几分钟/小时内转换它

datetime android json android-parser

7
推荐指数
1
解决办法
2万
查看次数

列表视图滚动不平滑

我有一个自定义列表视图,显示用户,并有照片我从API检索数据,提供JSON输出,

我的问题是列表视图不能平滑滚动,它会挂起一秒钟并滚动,它会重复相同直到我们到达终点.

我认为这可能是因为我在UI线程上运行网络相关操作,但即使在完成加载后它仍然继续这样做?

我的自定义Listview的结构是

 <TextView  style="@style/photo_post_text"
             android:id="@+id/photo_post_text"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="demotext"
           />


        <ImageView
            android:id="@+id/userimage"
           android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scaleType="fitXY"

            android:adjustViewBounds="true"
           android:src="@drawable/pi" 
           />
Run Code Online (Sandbox Code Playgroud)

android android-listview android-scrollview android-scroll

4
推荐指数
1
解决办法
1万
查看次数