У меня проблема с элементами списка. Все элементы списка отображают последнее значение хеш-карты для всех элементов списка при нажатии на список. Как решить эту проблему. Я сделал кодировку следующим образом.элементов списка HashMap в виде списка отображаются только последние элементы
Код:
protected Void doInBackground(Void... params) {
HashMap<String, String> contact = new HashMap<String, String>();
DefaultHttpClient httpclient = new DefaultHttpClient();
try {
HttpGet httpget = new HttpGet(
url);
HttpResponse response = httpclient.execute(httpget);
String jsonResp = EntityUtils.toString(response
.getEntity());
Log.d("HTTP", "Rsponse : " + jsonResp);
if (jsonResp != null) {
JSONObject jsonObject1 = new JSONObject(jsonResp);
JSONArray jsonArray = jsonObject1.getJSONArray("values");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject2 = jsonArray.getJSONObject(i);
firstname = jsonObject2.getString(firstname);
lastname = jsonObject2.getString(lastname);
headline = jsonObject2.getString(headline);
pictureUrl = jsonObject2.getString(pictureUrl);
id = jsonObject2.getString(id);
JSONObject jsonObject3 = jsonObject2.getJSONObject("siteStandardProfileRequest");
url = jsonObject3.getString("url");
}
Log.d("HTTP", "firstname : " + firstname + "\n" + "lastName :"
+ lastname + "\n" + "headline : " + headline + "\n"
+ "pictureUrl :" + pictureUrl + "\n" + "id :"
+ id + "\n" + "Url :" + url);
contact = new HashMap<String, String>();
contact.put(TAG_ID, id);
contact.put(TAG_FNAME, firstname);
contact.put(TAG_LNAME, lastname);
contact.put(TAG_HLINE, headline);
contact.put(TAG_PURL, pictureUrl);
contact.put(TAG_URL, url);
contactList.add(contact);
}
} else {
Log.e("HTTP", "Couldn't get any data from the url");
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void result) {
super.onPostExecute(result);
if (pDialog.isShowing())
pDialog.dismiss();
SimpleAdapter adapter = new SimpleAdapter(
HomeActivity.this, contactList,
R.layout.list_item, new String[]{TAG_FNAME}, new int[]{R.id.textView1});
setListAdapter(adapter);
adapter.notifyDataSetChanged();
Collections.sort(contactList, new Comparator<Map<String, String>>() {
public int compare(final Map<String, String> o1, final Map<String, String> o2) {
return o1.get("firstname").compareTo(o2.get("firstname"));
}
});
lv.setTextFilterEnabled(true);
lv.setFastScrollEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View view, int position, long ids) {
Intent i = new Intent(getApplicationContext(),
SingleListActivity.class);
i.putExtra("id", id);
i.putExtra("firstname", firstname);
i.putExtra("lastname", lastname);
i.putExtra("headline", headline);
i.putExtra("pictureUrl", pictureUrl);
i.putExtra("url", url);
Log.v("Pass", "id :" + id + "\n" + "firstname :" + firstname + "\n"
+ "lastname :" + lastname + "\n" + "headline :" + headline
+ "\n" + "pictureUrl :" + pictureUrl + "\n"
+ "siteStandardProfileRequest" + url);
startActivity(i);
}
});
}
ContactList, где инициализируется эту переменную? –
Вы видели стоимость контактного списка, а также, пожалуйста, отсортируйте список перед данным списком для адаптера? –
почему HashMap contact = contactList.get (position); есть внутри listview onClick(). Вы не используете его нигде. Это называется Shadowing. Может быть, это и есть причина. –
ORIGINAL