在 Android 应用程序中检索 Drupal 站点数据的正确方法是什么?
假设我需要将 30 个数据节点检索到列表视图中,其中每一行都使用 layoutInflater。在我的情况下,我从 Json 代码中获取数据,然后将它们保存到数组中,然后将每个数据索引调用到 listView 行中。这是正确的方法吗?
使用 7 个数组来保存数据并继续该过程是否有效?我觉得它并不笨重和不灵活。我对吗?
已编辑 :: 添加了 JsonCode
receivedJson = Json.getJsonString(Constants.HOST_DOMAIN_NAME
+ serviceEndPoint);
try {
/*
* convert received Json String to Json array with
*
* @getDrupalFinalJsonArray: METHOD
*/
jsonArray = Json.getDrupalFinalJsonArray(receivedJson,
objectParent, itemParent);
/*
* Define the length of @nodeBodyArray, @nodeAutherNameArray to be
* the same length of sonArray but -1, since a factecus item added
* at index(0) this ISSUE SHOULD BE SOLvER !
*/
nodeTitleArray = new String[jsonArray.length() - 1];
nodeAuthorNameArray = new String[jsonArray.length() - 1];
nodeAuthorImageArray = new String[jsonArray.length() - 1];
nodeCommentCount = new int[jsonArray.length() - 1];
nodeNid = new int[jsonArray.length() - 1];
postDate=new String[jsonArray.length()-1];
nodeNid = Json.convertJsonArrayToIntJavaArray(jsonArray, "nid");
nodeCommentCount = Json.convertJsonArrayToIntJavaArray(jsonArray,
"commentcount");
nodeTitleArray = Json.convertJsonArrayToStringJavaArray(jsonArray,
"body");
nodeAuthorNameArray = Json.convertJsonArrayToStringJavaArray(
jsonArray, "author");
nodeAuthorImageArray = Json.convertJsonArrayToStringJavaArray(
jsonArray, "profile");
postDate=Json.convertJsonArrayToStringJavaArray(jsonArray, Constants.NODE_POST_DATE_TAG);
} catch (Exception e) {
}
adapter = new nodeListAdapter(context,
android.R.layout.simple_list_item_1, nodeTitleArray,
nodeAuthorNameArray, nodeAuthorImageArray, nodeCommentCount,
nodeNid,postDate); // define the list adapter