第一个JSON:
{
"datas":[
{
"id":"1",
"name":"Name 1",
"users":"1,3"
},
{
"id":"2",
"name":"Name 2",
"users":"2,5"
}
]
}
第二个JSON:
{
"users":[
{
"id":"1",
"name":"User 1"
},
{
"id":"2"
"name":"User 2"
}
......
]
}
但我总是得到所有用户的列表,无论我在哪里点击(名称1或名称2)
这就是我用来获取基于id的过滤用户:
@Override
protected Boolean doInBackground(String... urls) {
try {
String[] strMultiUsers = strEventUsers.split(",");
List<String> listMultiUsers = Arrays.asList(strMultiUsers);
HttpGet httppost = new HttpGet(urls[0]);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject jsono = new JSONObject(data);
JSONArray jarray = jsono.getJSONArray("users");
for (int i = 0; i < jarray.length(); i++) {
JSONObject object = jarray.getJSONObject(i);
UsersList oldEventsList = new UsersList();
oldEventsList.setId(object.getString("id"));
oldEventsList.setName(object.getString("name"));
if(listMultiUsers.contains(""))
{
}
oldEventsArrayList.add(oldEventsList);
}
return true;
}
我希望每当用户点击名称2时,我只需要显示两个用户(id为2和5的用户)但我仍然获得所有用户(1到5)
答案 0 :(得分:1)
我找到了解决方案,并为其他开发人员安排了:
String strUsers = object.getString("id").toString();
Log.d("users", strUsers);
usersList.setName(object.getString("name"));
if(listMultiUsers.contains(strUsers))
{
usersListArrayList.add(usersList);
}