Android 查询适配器重置
Android queried adapter reset
是否可以在不进行新查询的情况下将我的适配器重置为原始状态?
例如
我有 JSONArray
,我剪切了一些记录以显示在 ListView
中选择的,但我想重置数据并再次显示所有记录。这可能吗?
private JSONArray modifyJsonArray(JSONArray array, final Integer param) throws JSONException {
List<JSONObject> jsons = new ArrayList<JSONObject>();
for (int i = 0; i < array.length(); i++) {
Integer statusId = Integer.parseInt(array.getJSONObject(i).getString("statusId"));
if (statusId == param){
jsons.add(array.getJSONObject(i));
}
}
return new JSONArray(jsons);
}
private void selectStatus(JSONArray arr, Integer param) throws JSONException {
myArr= modifyJsonArray(arr, param);
adapter.notifyDataSetChanged();
}
我有一个微调器,其中包含所有 statusId 和选项 "All"。选择所有后,我需要显示所有 records.I 从简单微调器中选择状态 ID,然后调用 selectStatus(myArr, statusId)
问题是当我从数组中删除记录时,我无法将其恢复。
现在阅读下面的说明并按照它来找到您的解决方案,
首先创建变量外部方法如下,
List<JSONObject> mainJsons = new ArrayList<JSONObject>();
现在修改您的 modifyJsonArray 方法如下
private JSONArray modifyJsonArray(JSONArray array, final Integer param) throws JSONException
{
List<JSONObject> jsons = new ArrayList<JSONObject>();
mainJsons = new ArrayList<JSONObject>();
for (int i = 0; i < array.length(); i++)
{
Integer statusId = Integer.parseInt(array.getJSONObject(i).getString("statusId"));
mainJsons.add(array.getJSONObject(i));
if (statusId == param)
{
jsons.add(array.getJSONObject(i));
}
}
return new JSONArray(jsons);
}
现在创建一个重置主数组的方法如下
private void resetStatus(JSONArray arr) throws JSONException
{
if(arr != null && arr. size() > 0)
{
myArr = arr;
adapter.notifyDataSetChanged();
}
}
现在在你想要重置listviw的地方调用这个方法
resetStatus(new JSONArray(mainJsons));
是否可以在不进行新查询的情况下将我的适配器重置为原始状态?
例如
我有 JSONArray
,我剪切了一些记录以显示在 ListView
中选择的,但我想重置数据并再次显示所有记录。这可能吗?
private JSONArray modifyJsonArray(JSONArray array, final Integer param) throws JSONException {
List<JSONObject> jsons = new ArrayList<JSONObject>();
for (int i = 0; i < array.length(); i++) {
Integer statusId = Integer.parseInt(array.getJSONObject(i).getString("statusId"));
if (statusId == param){
jsons.add(array.getJSONObject(i));
}
}
return new JSONArray(jsons);
}
private void selectStatus(JSONArray arr, Integer param) throws JSONException {
myArr= modifyJsonArray(arr, param);
adapter.notifyDataSetChanged();
}
我有一个微调器,其中包含所有 statusId 和选项 "All"。选择所有后,我需要显示所有 records.I 从简单微调器中选择状态 ID,然后调用 selectStatus(myArr, statusId)
问题是当我从数组中删除记录时,我无法将其恢复。
现在阅读下面的说明并按照它来找到您的解决方案,
首先创建变量外部方法如下,
List<JSONObject> mainJsons = new ArrayList<JSONObject>();
现在修改您的 modifyJsonArray 方法如下
private JSONArray modifyJsonArray(JSONArray array, final Integer param) throws JSONException
{
List<JSONObject> jsons = new ArrayList<JSONObject>();
mainJsons = new ArrayList<JSONObject>();
for (int i = 0; i < array.length(); i++)
{
Integer statusId = Integer.parseInt(array.getJSONObject(i).getString("statusId"));
mainJsons.add(array.getJSONObject(i));
if (statusId == param)
{
jsons.add(array.getJSONObject(i));
}
}
return new JSONArray(jsons);
}
现在创建一个重置主数组的方法如下
private void resetStatus(JSONArray arr) throws JSONException
{
if(arr != null && arr. size() > 0)
{
myArr = arr;
adapter.notifyDataSetChanged();
}
}
现在在你想要重置listviw的地方调用这个方法
resetStatus(new JSONArray(mainJsons));