创建Android应用列表 [英] Create list in android app

查看:215
本文介绍了创建Android应用列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道一个很好的方法来创建我的Andr​​oid应用程序列表。我把所有的信息在我的数据库,并希望从中我每次启动应用程序时加载数据,并从中列表(ID和标题)。

I want to know a good way to create a list in my android app. I have all info in my DB and want to load data from it each time I start the app and make a list from it (id and title).

什么是最好的方法呢?

What is the best approach?

我应该做一个PHP脚本,与一个JSON EN $ C $光盘阵列,所有列表项响应,或者我应该做一个XML文件,该文件生成每次在数据库中的数据变化,我导入到每个应用程序一次启动?或任何其他好办法呢?

Should I make a PHP-script that responds with a JSON encoded array with all list items or should I make an XML-file that generates each time the data in the DB changes that I import to the app each time it starts? or any other good way to do it?

由于所有的东西都用XML的文件在android系统使得它感觉像导入XML将是一个很好的事情,是吗?而如何导入从Web服务器的XML文件到应用程序?

Since all stuff are made by XML-files in android it feels like importing a XML would be a good thing, is it? And how do I import an XML-file from a web server into the app?

//丹尼尔

推荐答案

在您的情况我会选JSON基于XML在下面的帖子中规定的所有原因的:的 http://ajaxian.com/archives/json-vs-xml-the-debate

In your situation I would pick JSON over XML for all the reason's stated in the following post: http://ajaxian.com/archives/json-vs-xml-the-debate

此外,在Android中,有默认内置JSON数组的,所以你不必做code的任何额外的传球。

Plus, in android, there are JSON Array's built in by default so you don't have to do any extra passing of the code.

return new JSONArray("my json string goes here..."); 

由于我们所谈论的是移动设备,我总是会产生你的PHP脚本的变化,而不是有一个完全同步,因为这将是大小完全同步小了很多。但是,你需要给你的用户一个选项,做一个完整的重新同步,如果这是适用于您的应用程序。我会用一个SQLite数据库来存储数据,并且仅更新改变在于

Since we are talking about a mobile device, I would always generate changes in your php script rather than have a full sync as this will be a lot smaller in size that a full sync. However, you will need to give your user a option to do a full re-sync if this is applicable to your app. I would use a SQLite database to store the data and only update the changes in that.

要还使流较小,可以gzip压缩COM preSS从PHP的输出这可以通过Android设备来阅读本身。在我的应用程序,我COM preSS 500KB到110KB〜传输性能上,一个巨大的节省了。如何读取流这里的部分​​例如:

To also make the stream smaller, you can gzip compress your output from php as this can be natively read by the android device. In my app, I compress 500kb down to ~110kb before transmitting, a huge saving on performance. Here a partial example of how to read the stream:

InputStream in = null;
HttpURLConnection httpConn = null; // you will have to write your on code for this bit.

if (httpConn.getContentEncoding() != null) 
{
String contentEncoding = httpConn.getContentEncoding().toString();
if (contentEncoding.contains("gzip")) 
{ 
    in = new GZIPInputStream(httpConn.getInputStream());
}
} 
else 
{ 
    in = httpConn.getInputStream();
}

我希望这一切是有道理的,它是一个漫长的一天编程:)

I hope that this all makes sense, it's been a long day programming :)

斯图

这篇关于创建Android应用列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆