일부 항목이있는 ListView가 있지만 데이터베이스를 업데이트 한 후 ListView를 "새로 고침"하고 싶습니다. 누구든지 나를 도울 수 있습니까?ListView 새로 고침 항목
편집 : populateListView이
public void populateListView()
{
String URL = config.getUrl_For_Query() + ",&nameq=Select&tipo=select"; // my URL
String jsonString = reading.execute_query(URL); // jsonString is formatted well
try
{
JSONObject jsonResponse = new JSONObject(jsonString);
JSONArray array = jsonResponse.getJSONArray("elenco");
for (int i=0; i<array.length(); i++) // I scan all array
{
JSONObject nameObj = (JSONObject)array.get(i);
// I retrieve all information
allNames.add(nameObj.getString("name")); // Name
allLng.add(nameObj.getString("lng")); // Another information
}
}
catch (Exception e)
{ e.printStackTrace(); }
List<String> Array = new ArrayList<String>();
for(int i=0;i<allNames.size();i++) // I add all values
{
String value = allNames.get(i).toString() + ", \n\t" + allLng.get(i).toString();
Array.add(value); // here I populate my Array
}
final ListView listView = (ListView) getActivity().findViewById(R.id.List);
listView.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, Array));
//
// Click
//
}
saveChanges를
public void saveChanges()
{
// I update a Database
// And then I'd like to refresh ListView's items
populateListView(); // Update ListView
}
그리고 정확히 무엇이 문제입니까? –
문제는 새 항목이 다른 항목 아래에 추가된다는 것입니다. – 1megg1
매번 새로운 '어댑터'를 만들어 문제가 배열을 채우는 방법에 있어야합니다. 코드를 입력하십시오. 나는 우리가 그곳에서 오류를 발견 할 것이라고 확신한다. –